forum

Home / DeveloperSection / Forums / How to require text in a Textbox?

How to require text in a Textbox?

Allen Scott 1768 25-Nov-2014

How do I go about requiring text in a textbox? This is what i have so far. 

String strName = txtName.Text;
String strEmail = txtEmail.Text;
Boolean blnErrors = false;
 
if (strName == null)
{
 
}
else
{
    string script ="alert(\"Name Field Is Required!\");";
    ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);
 
    txtName.Focus();
}

When I run the program and try to execute it, I get the error popping up regardless if I have text entered into the textbox or not. I only want the Error to show if There is Nothing in the TextBox. I have also tried using, 

if (strName == "")

as well. But nothing changes.


Updated on 26-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By