TextBox textchange event inside usercontrol

2.4k Views Asked by At

I want to trigger textchange event of txtPlanCode inside the usercontrol but unfortunately my textchange is not triggered. whats wrong with my code?

Please help thanks :)

 //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>
1

There are 1 best solutions below

1
On

on user control :

  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>

on page :

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