最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于兩個自定義控件的取值問題及接口的應(yīng)用

 更新時間:2013年01月27日 12:34:31   作者:  
一個.aspx的頁面中,用到了兩個用戶控件,其中想做的到A控件有一個按鈕,點擊的時候獲取到B控件中的一個textbox的值想必大家會使用findcontrol獲取控件吧,而在生成的時候名字是不確定的,那么如何書寫呢?接下來為您提供詳細(xì)的解決方法,感興趣的朋友可以了解下啊
“一個.aspx的頁面中,用到了兩個用戶控件,其中想做的到A控件有一個按鈕,點擊的時候獲取到B控件中的一個textbox的值。

因為在生成的時候名字會改變,用findcontrol的時候名字該如何寫呢?
另外像這種問題有幾種解決的辦法呢?”

論壇上看到這個問題,Insus.NET提供自己的解決方法,先看看解決運行的效果:
 
首先創(chuàng)建一個站點,然后創(chuàng)建兩個用戶控件,一個是UcA,一個是UcB。 在UcB的控件上拉一個TextBox。
復(fù)制代碼 代碼如下:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UcB.ascx.cs" Inherits="UcB" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

創(chuàng)建一個接口IGetValue:
復(fù)制代碼 代碼如下:

IGetValue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for IGetValue
/// </summary>
namespace Insus.NET
{
public interface IGetValue
{
string GetValue();
}
}

接下來,用戶控件UcB實現(xiàn)這個接口,接口返回TextBox的Text值。
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class UcB : System.Web.UI.UserControl,IGetValue
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetValue()
{
return this.TextBox1.Text.Trim();
}
}

創(chuàng)建一個aspx頁面,如Default.aspx,切換至設(shè)計模式,把兩個用戶控件UcA,UcB拉至Default.aspx:
復(fù)制代碼 代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="UcA.ascx" TagName="UcA" TagPrefix="uc1" %>
<%@ Register Src="UcB.ascx" TagName="UcB" TagPrefix="uc2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<fieldset>
<legend>UcA
</legend>
<uc1:UcA ID="UcA1" runat="server" />
</fieldset>
<fieldset>
<legend>UcB
</legend>
<uc2:UcB ID="UcB1" runat="server" />
</fieldset>
</form>
</body>
</html>

到這里,再創(chuàng)建一個接口Interface,目的是為了獲取UcB這個用戶控件。
復(fù)制代碼 代碼如下:

IGetUserControl.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
/// <summary>
/// Summary description for IGetUserControl
/// </summary>
namespace Insus.NET
{
public interface IGetUserControl
{
UserControl GetUc();
}
}

接口創(chuàng)建好之后,在Default.aspx.cs實現(xiàn)這個IGetUserControl接口。
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page,IGetUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public UserControl GetUc()
{
return this.UcB1;
}
}

到最后,我們在UcA這個用戶控件的按鈕Click事件寫:
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class UcA : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
IGetUserControl ucb = (IGetUserControl)this.Page;
IGetValue value = (IGetValue)ucb.GetUc();
Response.Write("<scr" + "ipt>alert('" + value.GetValue() + "')</scr" + "ipt>");
}
}

相關(guān)文章

  • asp.net下 jquery jason 高效傳輸數(shù)據(jù)

    asp.net下 jquery jason 高效傳輸數(shù)據(jù)

    jquery jason 高效傳輸數(shù)據(jù)轉(zhuǎn)自網(wǎng)上稍有修改
    2009-03-03
  • ASP.NET中控件的EnableViewState屬性及徹底禁用

    ASP.NET中控件的EnableViewState屬性及徹底禁用

    如果我們在開發(fā)Web應(yīng)用程序時,某些控件是不需要接受用戶的操作或只需要接受一次操作的時候,我們可以將這些控件的EnableViewState屬性改為false,這樣可以優(yōu)化我們的程序,提高網(wǎng)絡(luò)訪問的速度。
    2016-06-06
  • 使用Lucene.NET實現(xiàn)站內(nèi)搜索

    使用Lucene.NET實現(xiàn)站內(nèi)搜索

    提到Lucene,想必大家都有所耳聞,已經(jīng)是數(shù)年前就出現(xiàn)的開源技術(shù)。很多站點都是利用它搭建自己網(wǎng)站的站內(nèi)搜索。由于最近也在做數(shù)據(jù)檢索方面的東西,也學(xué)習(xí)了下Lucene.net的使用。
    2015-06-06
  • 淺談AjaxPro.dll,asp.net 前臺js調(diào)用后臺方法

    淺談AjaxPro.dll,asp.net 前臺js調(diào)用后臺方法

    這篇文章主要介紹了淺談AjaxPro.dll,asp.net 前臺js調(diào)用后臺方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • .Net解決引用程序集沒有強名稱報錯

    .Net解決引用程序集沒有強名稱報錯

    這篇文章介紹了.Net解決引用程序集沒有強名稱報錯的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • asp.net core 授權(quán)詳解

    asp.net core 授權(quán)詳解

    在本篇文章里小編給大家整理了關(guān)于asp.net core 授權(quán)的相關(guān)知識點內(nèi)容,需要的朋友們學(xué)習(xí)下。
    2020-01-01
  • C#時間格式化(Datetime)用法詳解

    C#時間格式化(Datetime)用法詳解

    C#時間格式化Datetime.ToString參數(shù)format格式詳細(xì)用法,本文將進行介紹,感興趣的朋友可以了解下啊
    2013-01-01
  • asp.net為網(wǎng)頁動態(tài)添加關(guān)鍵詞的方法

    asp.net為網(wǎng)頁動態(tài)添加關(guān)鍵詞的方法

    這篇文章主要介紹了asp.net為網(wǎng)頁動態(tài)添加關(guān)鍵詞的方法,可實現(xiàn)動態(tài)添加keyword meta的功能,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • Asp.net MVC 對所有用戶輸入的字符串字段做Trim處理的方法

    Asp.net MVC 對所有用戶輸入的字符串字段做Trim處理的方法

    這篇文章主要介紹了Asp.net MVC 如何對所有用戶輸入的字符串字段做Trim處理,需要的朋友可以參考下
    2017-06-06
  • C#頁碼導(dǎo)航顯示及算法實現(xiàn)代碼

    C#頁碼導(dǎo)航顯示及算法實現(xiàn)代碼

    C#頁碼導(dǎo)航算法要求:頁數(shù)小于等于1時不顯示;頁數(shù)大于10時,自動縮短,需要的朋友可以了解下
    2012-12-12

最新評論

南岸区| 旅游| 临高县| 德庆县| 前郭尔| 突泉县| 海口市| 沾益县| 高州市| 上饶县| 开鲁县| 苗栗市| 麻城市| 保定市| 南宁市| 原平市| 菏泽市| 秀山| 措美县| 桦甸市| 青州市| 江华| 镇原县| 乌兰浩特市| 休宁县| 莒南县| 铁岭县| 法库县| 东乌| 本溪| 聊城市| 通河县| 沁水县| 苗栗市| 洪湖市| 新乡市| 通州市| 彰化县| 杨浦区| 察哈| 河津市|