ASP.NET - check the value in textbox is null or not.

Asked By Gopi K on 18-May-10 01:18 AM


     I have a textbox in my page. i want to check the textbox value in another textbox text_changed code the first textbox value is null or not...


      I used this code  textbox.text==" ", textbox.text==null , but it not works.......


     Any one help me.

      Thanks In Advance.......
Mash B replied to Gopi K on 18-May-10 01:26 AM
try with below code

if( string.IsNullOrEmpty(TextBox1.Text))
            {

            }
Anand Malli replied to Gopi K on 18-May-10 01:28 AM
Hi Gopi

you have to write following code to achive this

if(!string.IsNullOrEmpty(txt.Text))
{
   // your code
}

this will check for null as well as blank,so no need to check two condition

let me know when you are done

thxs
Mash B replied to Gopi K on 18-May-10 01:30 AM
if u want client side validation then use below javascript

<script language="javascript" type="text/javascript">
function validate()
{
      if (document.getElementById("<%=txtName.ClientID%>").value=="")
      {
                 alert("Name Feild can not be blank");
                 document.getElementById("<%=txtName.ClientID%>").focus();
                 return false;
      }
Anoop S replied to Gopi K on 18-May-10 01:38 AM
You can use this also
if (textBox1.Text.Trim().Length == 0)
  {
      //Your code
   }
Web Star replied to Gopi K on 18-May-10 02:06 AM
hi, check as follows this work perfectly in my project
if(txtbox.Text.ToString() == "")
{

}

if this doesn't help u than u should check value of txtbox.Text.ToString() by using break point may be there some thing found u if not than let me know with your details code.
Gopi K replied to Mash B on 18-May-10 04:38 AM


    Thanks Pal,

                     It works, thank you once again for your nice answer........
Gopi K replied to Anoop S on 18-May-10 04:40 AM


Thanks Pal
                        

               It Works, Thank you once again for your nice answer..........
Gopi K replied to Anand Malli on 18-May-10 04:41 AM
Thanks Pal
                        

               It Works, Thank you once again for your nice answer..........
snehal replied to Gopi K on 17-Mar-11 04:36 AM
superrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrb answer plz. do help me m trainee
muniram replied to Gopi K on 06-Jun-11 06:01 AM
string s=textbox1.text;
if(s=="")



I think u got it
muniram replied to Gopi K on 06-Jun-11 06:01 AM
string s=textbox1.text;
if(s=="")



I think u got it