Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello experts,

am working on asp.net login page, in this i have 2 textboxes and login button.

My requirement is user can only click the login button if the text is entered in textboxes.

Just I want to enable login button, when text is entered in textbox.

Please can you help me how to do this.

thanks forever.
Posted

Try this way:
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   if(TextBox1.Text.Trim().Length > 0)
   {
      Button.Enabled = true;
   }
}

Refer more detailed description about textchanged event[^]
 
Share this answer
 
Comments
VICK 24-Jun-13 8:23am    
Hi Prasad... I have a question .. ie.. forexample if i have the same scenario but i want the button to be enabled after both textboxes got filled than can i do that in the following way or can u guide me in this regard,

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if(TextBox1.Text.Trim().Length > 0 && TextBox2.Text.Trim().Length > 0 )
{
Button.Enabled = true;
}
}
Prasad_Kulkarni 24-Jun-13 8:49am    
Hello Khan Ji,

The above code will not work as on you're not moved to second text box and this
&& TextBox2.Text.Trim().Length > 0 condition always fails.

You need to do something like:

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Length > 0)
{
if (textBox2.Text.Trim().Length > 0)
{
dataGridView1.Visible = true;
}

}
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox1_TextChanged(sender, e);
}

Hope it helps!
VICK 24-Jun-13 8:53am    
ahan.. thanks dear.. now got cleared.. :)
Prasad_Kulkarni 24-Jun-13 8:55am    
Glad to here!
Call a javascript function onchange event of textbox. There you can do this
JavaScript
document.getElementById("your button id").disabled = false;
 
Share this answer
 
v2
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   if(TextBox1.Text1 != 0)
   {
      Button.Enabled = true;
   }
}
 
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