我想在usercontrol中触发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>
答案 0 :(得分:4)
关于用户控制:
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>