Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Why ontextchanged event of textbox isnot working after postback

XML
<div class="col-md-6">

                                <asp:TextBox ID="txtname" runat="server" class="form-control"
                            meta:resourcekey="txtnameResource1" AutoPostBack="True" ontextchanged="txtname_changed"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ReqName" runat="server"
                    ControlToValidate="txtname" Display="Dynamic"
                    ErrorMessage="Please Enter Name"
                            meta:resourcekey="RequiredFieldValidator3Resource1"></asp:RequiredFieldValidator>
                    </div>



C#
protected void txtname_changed(object sender, EventArgs e)
       {
           int Count = m.bussinesCollection.SubscriptionKindBL.GetSubscriptionkindbyname(txtname.Text.ToString());

           if (Count != 0)
           {
               lblmessage.Visible = true;
               lblmessage.Text = "User Name is Already Exist";

           }
           else
           {
               lblmessage.Visible = false;
               m.bussinesCollection.SubscriptionKindBL.Name = txtname.Text;

           }
       }




my code works fine but during debugging i found that,when i change value in textbox if it is repatly come then that vaLUE CAN'T CHANGE.

and i can't enter new value without page refresh.

Ex. suppose i enter Asp.net in this textbox,if asp.net is already enter means it is exist in database,then labelmsg is shown.but when i try to change this value i found that if i enter any value like abcd then textbox's value become Asp.net repeatly till i not page refresh.

can anyone give me solution for that.?

Thanks in advance.
Posted

Make Text Box blank after showing error message & if u want to show entered text value also then make it visible in your error message like

C#
lblmessage.Text = "'Your entered text' is Already Exist";
 
Share this answer
 
Comments
ketan italiya 23-Jan-14 4:59am    
thanks for solution but it not help me,when debug my code,after value change i found that ontextchanged is not work .first time it work
Change the property of your text box to enableViewState=false and AutoPostback=true
 
Share this answer
 
Comments
ketan italiya 23-Jan-14 5:00am    
thanks for solution but it not help me,when debug my code,after value change i found that ontextchanged is not work .first time it work,when i enter Asp.net but after delete this value from textbox i try to enter abcd but Asp.net comes automatically
try to implement this separately on another page,if works then may other factors from original page are affecting functionality. Because when i done this, i not found such type of issue.
 
Share this answer
 

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



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