Checking for a value in a string...

darwin916com

New Member
In ASP I used to be able to check a string variable for value by doing something like...<BR><BR>If strText = "" Then<BR> strText = "Nothing"<BR>Else<BR> strText = "Something"<BR>End<BR><BR>...but in Asp.Net (VB) that does not work, using double "" marks does not work for detecting a NULL value. So I also tried...<BR><BR>If strText = Nothing Then<BR><BR>and<BR><BR>If Not strText <> Is Nothing Then<BR><BR>....but none of these work. I am looking for an easy way to see if a string has a value in it or if itis empty. Actually, I am not using a string I am using the text value of a text box like...<BR><BR>If Name.Text = Nothing Then<BR><BR>...and I am trying to see if that text box (an asp:textbox) has data in it or not.<BR><BR>Anybody have any ideas on this one???<BR><BR>Thanks,<BR>Matt<BR>Use the Length property of the String class:<BR><BR>If txtUsername.Length = 0 then<BR> 'the user didn't enter any information<BR>End If<BR><BR>On an asside, when doing form validation in ASP.NET, you really ought to let ASP.NET's validation controls do all of the work for you. See this article for more detail:<BR>http://www.4guysfromrolla.com/webtech/090200-1.shtml<BR><BR>Happy Programming!
 
Back
Top