C# 带有文本框的Usercontrol操作事件
我是asp.net新手, 我的问题是我在default.aspx中有一个文本框和用户控件按钮,单击该按钮后,我需要更改文本框的文本值(用户控件的一些默认值) 有可能吗?如果有,我需要在哪里写代码 Default.aspxC# 带有文本框的Usercontrol操作事件,c#,.net,asp.net,user-controls,C#,.net,Asp.net,User Controls,我是asp.net新手, 我的问题是我在default.aspx中有一个文本框和用户控件按钮,单击该按钮后,我需要更改文本框的文本值(用户控件的一些默认值) 有可能吗?如果有,我需要在哪里写代码 Default.aspx <%@ Register Src="Text.ascx" TagName="Edit" TagPrefix="uc1" %> <asp:TextBox ID="TextBox1" runat="server" Width="262px"></as
<%@ Register Src="Text.ascx" TagName="Edit" TagPrefix="uc1" %>
<asp:TextBox ID="TextBox1" runat="server" Width="262px"></asp:TextBox>
<uc1:Edit Id="Edit2" runat="server" /></td>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Text.ascx.cs" Inherits="WebApplication4.WebUserControl1" %>
<asp:Button ID="Button1" runat="server" Text="Edit " OnClientClick="return confirm('Are you certain you want to Navigate?');" Width="341px" onclick="Button1_Click" />
用户控制-按钮
<%@ Register Src="Text.ascx" TagName="Edit" TagPrefix="uc1" %>
<asp:TextBox ID="TextBox1" runat="server" Width="262px"></asp:TextBox>
<uc1:Edit Id="Edit2" runat="server" /></td>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Text.ascx.cs" Inherits="WebApplication4.WebUserControl1" %>
<asp:Button ID="Button1" runat="server" Text="Edit " OnClientClick="return confirm('Are you certain you want to Navigate?');" Width="341px" onclick="Button1_Click" />
如何对用户控件进行分组或触发(文本框值更改)?在
按钮1\u单击按钮1
的事件中,您可以使用Page.FindControl()
方法获取对文本框的引用,如下所示:
protected void Button1_Click(...)
{
TextBox txtBox = (TextBox)this.Page.FindControl("TextBox1");
if(txtBox != null)
txtBox.Text = "Set some text value";
}
从用户控件开始:
<asp:Button ID="Button1" runat="server" Text="Edit "
OnClientClick="return confirm('Are you certain you want to Navigate?');"
Width="341px" onclick="Button1_Click"/>
“Default.aspx”页面将包含新自定义事件的事件处理程序。
标记:
protected void EditClick_OnEditClick(object sender, TestApplication.Edit.EditEventArgs e)
{
TextBox1.Text = e.Data;
}