好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 關于兩個自定義控件的取值問題及接口的應用

關于兩個自定義控件的取值問題及接口的應用

熱門標簽:申請400電話手續 百度ai地圖標注 同安公安400電話怎么申請流程 南陽外呼系統定制化 合肥電銷外呼系統哪家公司做的好 玉林市機器人外呼系統哪家好 預測式外呼系統使用說明 蘋果手機凱立德地圖標注 電話機器人軟件銷售工作
“一個.aspx的頁面中,用到了兩個用戶控件,其中想做的到A控件有一個按鈕,點擊的時候獲取到B控件中的一個textbox的值。

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

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

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

創建一個接口IGetValue:
復制代碼 代碼如下:

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實現這個接口,接口返回TextBox的Text值。
復制代碼 代碼如下:

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();
}
}

創建一個aspx頁面,如Default.aspx,切換至設計模式,把兩個用戶控件UcA,UcB拉至Default.aspx:
復制代碼 代碼如下:

%@ 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>

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

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();
}
}

接口創建好之后,在Default.aspx.cs實現這個IGetUserControl接口。
復制代碼 代碼如下:

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事件寫:
復制代碼 代碼如下:

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>");
}
}
您可能感興趣的文章:
  • .Net WInform開發筆記(三)談談自制控件(自定義控件)
  • asp.net自定義控件回發數據實現方案與代碼
  • asp.net中使用自定義控件的方式實現一個分頁控件的代碼
  • asp.net DropDownList自定義控件,讓你的分類更清晰
  • Asp.net 動態加載用戶自定義控件,并轉換成HTML代碼
  • asp.net 自定義控件實現無刷新上傳圖片,立即顯示縮略圖,保存圖片縮略圖
  • asp.net自定義控件代碼學習筆記
  • asp.net 虛方法、抽象方法、接口疑問

標簽:嘉興 南昌 臺州 揚州 南京 南京 海南 淄博

巨人網絡通訊聲明:本文標題《關于兩個自定義控件的取值問題及接口的應用》,本文關鍵詞  關于,兩個,自定義,控件,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《關于兩個自定義控件的取值問題及接口的應用》相關的同類信息!
  • 本頁收集關于關于兩個自定義控件的取值問題及接口的應用的相關信息資訊供網民參考!
  • 推薦文章