控制1:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cntrlIPSEntry.ascx.cs" inherits="ServiceManagement.Control.cntrlIPSEntry" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<asp:TextBox ID="txtModel" CssClass="form-control" runat="server"></asp:TextBox>
另一个控件:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomerInfo.ascx.cs" Inherits="ServiceManagement.Control.CustomerInfo" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<%@ Register Src="~/Control/cntrlIPSEntry.ascx" TagPrefix="uc1" TagName="cntrlIPSEntry" %>
<asp:Button CssClass="btn btn-default" ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click"/>
在C#中我想捕获txtModel的控件1数据
protected void btnSave_Click(object sender, EventArgs e)
{
//??
}
答案 0 :(得分:0)
我认为你要找的是FindControl
。您首先找到控件,将TextBox保存在Parent中,在本例中为Control,ID为WebUserControl1
。然后,只需找到正确的TextBox并将其转换为一个。
TextBox textBox = this.Parent.FindControl("WebUserControl1").FindControl("txtModel") as TextBox;
Label1.Text = textBox.Text;