Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I have 2 textbox i want when i write something in the ferst the seconde will disable
this is the code

XML
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged"></asp:TextBox>

        <asp:TextBox ID="TextBox3" runat="server" Enabled="False"></asp:TextBox>



C#
protected void TextBox2_TextChanged(object sender, EventArgs e)
        {

                if (TextBox2.Text != "")
                {
                    TextBox3.Enabled = false;
                }
                else
                {
                    TextBox3.Enabled = true;
                }
         }


but when i write something in textbox2 the Textbox don't disable plz help me
Posted

1 solution

Hi,

You'll need to perform a postback for the TextChanged handler to fire, adding the AutoPostBack attribute with a value of True will do this for you.

Something like this:
ASP.NET
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="True"></asp:TextBox>


... hope it helps.
 
Share this answer
 
v2
Comments
Member 11573837 15-Apr-15 9:37am    
hi,
it dosen't work
and i put a stop point in protected void TextBox2_TextChanged(object sender, EventArgs e) and it dosen't execute
hypermellow 15-Apr-15 9:42am    
... then there must be some other reason that is preventing the postback from occurring.

Can you post the rendered html markup the page produces for this control?

Member 11573837 15-Apr-15 9:56am    
can you test it in your machine plz !!
hypermellow 15-Apr-15 10:10am    
Work fine on my machine - the postback occurs when I move focus from TextBox2.

Here is the generated markup of TextBox2 where the client side change and keypress events are defined:

<input name="ctl00$MainContent$TextBox2" id="MainContent_TextBox2" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MainContent$TextBox2\',\'\')', 0)" type="text"/>

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