gpt4 book ai didi

c# - 用户控件内的 TextBox textchange 事件

转载 作者:行者123 更新时间:2023-11-30 20:45:54 25 4
gpt4 key购买 nike

我想在用户控件中触发 txtPlanCode 的 textchange 事件,但不幸的是我的 textchange 没有被触发。我的代码有什么问题?

请帮忙谢谢:)

 //CodeBehind of my page
protected void ucPlan_OnTextChanged(object sender, EventArgs e)
{
TxtPlanDesc.Text = Session["PlanDesc"].ToString();
}

//Client side (.aspx)

<uc2:PlanID ID="ucPlanCode" runat="server" ucPlan_OnTextChanged="ucPlan_OnTextChanged" autopostback="true"/>

//ucPlanID.ascx.cs

protected void Page_Load(object sender, EventArgs e)
{

}

public string PlanID
{
get
{
return txtPlanCode.Text;
}
set
{
txtPlanCode.Text = value;
}
}

public bool AutoPostBack
{
get
{
return txtPlanCode.AutoPostBack;
}
set
{
txtPlanCode.AutoPostBack = value;
}
}

//ucPlanID.ascx

<asp:TextBox ID="txtPlanCode" runat="server" CssClass="form-control" MaxLength="20" Enabled="true" Text='<%#Eval("PlanCode") %>' OnTextChanged="txtPlanCode_TextChanged"></asp:TextBox>

最佳答案

关于用户控制:

  public event EventHandler TextChangeEvent;

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (TextChangeEvent != null)
TextChangeEvent(this, e);
}

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>

在页面上:

<script runat="server">
protected void Some_TextChanged(object sender, EventArgs e)
{
// your code here
}
</script>

关于c# - 用户控件内的 TextBox textchange 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27604635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com