ASP.NET textbox textchange with same text input

3.4k views Asked by At

My ASP.NET page has a text box (say TextBox1). I used TextChanged event of the TextBox1 to fill some other text boxes on the same page. Here is the problem:

  • When the user has entered some text for the first time and lose the focus on the TextBox1, TextChanged event get fired and everything works as it should be.
  • But if the user has entered the same input as the first time, TextChanged event doesn't get fired. (because no text changes between the postbacks)

I want to fire a server side event whether user input the same text or different text. So the rest of the page get updated in both cases. Any method or workaround for this ?

Code behind language is C#.

Edited: codes added.

ASP page

<asp:TextBox ID="txtClientNumber"  AutoPostBack="true"  
    runat="server" Width="100px"  onFocus="select()"
    OnTextChanged="txtClientNumber_TextChanged"  ></asp:TextBox>

C#

protected void txtClientNumber_TextChanged(object sender, EventArgs e)
{ 
 //txtName.Text = ...<get data from SQL Server >..
 //other codes
} 

Thanks.

1

There are 1 answers

4
Alexander Bell On

The question is rather broad, so the answer is a bit generic. For this purpose, use ASP.NET TextBox1 OnTextChanged event and set the property AutoPostback="True".

Also, you can handle this event in client-side scripting by adding the attribute to TextBox1 control: TextBlock1.Attributes.Add("onblur","SomeJavascriptFunction()");

Hope this may help.