Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have set autopostback property true. And on textchanged event I've written some code. When 1st time I enters a value ans press tab then textchanged event is getting fired, but second time when I enters some same value and press tab or just enters tab then TextChenged event is not firing.
Please provide me solution

Here is my code:
.aspx code:

XML
<asp:TextBox ID="txtRegNo2" runat="server" CssClass="txtbox" TabIndex="81"  onBlur="javascript:CheckRegistrationNo(1,3,this)" AutoPostBack="True" ontextchanged="txtRegNo2_TextChanged" ToolTip="R2 must be 1 to 3 characters" MaxLength="3"></asp:TextBox>




C# code:
C#
protected void txtRegNo2_TextChanged(object sender, EventArgs e)
  {
      try
      {
         if ((txtRegNo1.Text != "") && (txtRegNo2.Text != ""))
          {
              pc.LicensePlateOne = txtRegNo1.Text;
              pc.LicensePlateTwo = txtRegNo2.Text;


              DataTable dt = new DataTable();

              dt = hd.GetRTO_Location(pc);

              if (dt.Rows.Count > 0)
              {
                  ddlRegLoc.SelectedValue = dt.Rows[0]["ID"].ToString();
                  ddlRegLoc.Enabled = false;

                  pd.ID = 3;
                  pd.ProductId = Session["ProductId"].ToString();
                  pd.RegLocationId = ddlRegLoc.SelectedValue;

                  DataTable dtZone = new DataTable();
                  dtZone = hd.GetLocationaDetails(pd);
                  if (dt.Rows.Count > 0)
                  {
                      ddlZone.DataTextField = dtZone.Columns["Description"].ToString();
                      ddlZone.DataValueField = dtZone.Columns["ID"].ToString();
                      ddlZone.DataSource = dtZone;
                      ddlZone.DataBind();
                  }
              }
              txtRegNo3.Focus();
          }
          else
          {
              ddlRegLoc.SelectedValue = "0";
              ddlRegLoc.Enabled = true;
          }
      }
      catch (SqlException sqlEx)
      {
          if (sqlEx.Number == -2)
          {
              string error = sqlEx.Message;
              ErrorLogs(error);
              Alert.Show("Timeout occured. Please try later");
          }
      }
      catch (Exception ex)
      {
          string error = ex.Message;
          ErrorLogs(error);
      }
  }
Posted
Updated 5-Sep-13 20:20pm
v6
Comments
phil.o 6-Sep-13 2:23am    
If the text does not change, what is the point the execute your method again ?
If some other fields are involved in the process, the you should assign the same method for the TextChanged event of every TextBox involved in the process. This way, everytime a TextBox involved gets its Text property changed, then your method will execute. If nothing has changed, nothing happens.
Dipali_Wagh 6-Sep-13 2:26am    
I want to execute it again and again because I've used one more text box and depends on values of both textbox I'm fetching some value from database
Dholakiya Ankit 6-Sep-13 3:31am    
use ajax instead will be faster then this

1 solution

Well this is how it works, text change event only get fired if your text is changed, if you entered “abc” first time and second time you have entered “abc” again then ASP.Net will compare last value with this new value if both are same then text change event will not get fired.
 
Share this answer
 
Comments
Dipali_Wagh 6-Sep-13 2:06am    
so what is the solution for this problem?
Mahesh Bailwal 6-Sep-13 2:21am    
Do you need to fire this text change event in every post back even if the value entered last time and this time is same?
Dipali_Wagh 6-Sep-13 2:24am    
ya right
I want to fire textchanged event every time
Mahesh Bailwal 6-Sep-13 2:32am    
So in that case create a separate function, copy all the content of “txtRegNo2_TextChanged” event inside this function and call this new fumction in every post back. Also delete “txtRegNo2_TextChanged” event.
Dipali_Wagh 6-Sep-13 2:35am    
means? I'm not getting it.
How to call it?
can u explain me?
bcoz anyway "txtRegNo2_TextChanged" event fires on every postback

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900