.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

When to check if something Is Nothing? How do you check an empty textbox?

Posted By:      Posted Date: October 15, 2010    Points: 0   Category :ASP.Net

I currently do something like...

If TextBox1.Text Is Nothing OR Trim(TextBox1.Text) = "" Then

' Do whatever

End If

Now I know this works.. but what is the right way to have this? I don't want to be checking something twice instead of just having it written out once.

View Complete Post

More Related Resource Links

how to check a textbox value in jquery?



I want to perform some action when an asp.net textbox value length is greater than 1 character. And for this I wanted to know how to write this check in jquery?

I have created a check like below-

if ($('[id=txtUserInput]').val().length > 2)
{ do some work...} 

But its giving me the following error

$("[id=txtUserInput]").val() is undefined

Can anybody let me know the right way of doing this?



How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

TreeView (icon+check+label+textbox) binded to a recursive dataset

Hello dudes, I have a DataSet with a DataTable and I want to populate a TreeView with it's contents:Id, IntParentId, IntName,StringIcon, ???Checked, IntValue, Intthe nodes must look like:   (icon) [checked] - Name |Value|there are 2 fields updatable, checked and value, and changes made by user in the tree must update the datatable/rowI was the last 2 day looking for how to build a tree like this and have no ideas..... tks :)

how to check if a Dataview is empty?

I am having trouble with the syntax to check if my Dataview is empty.  If it is empty then the next line when I try draw information from it generates an error. How can I fix this?Dim ProjectDV As DataViewDim arg As New DataSourceSelectArgumentsProjectDV = SqlDataSource1.Select(arg)   If ProjectDV.Count <> 0 ThenpicAd.Text = LCase(ProjectDV(0)("Ad"))End If  

How can you check the user is owned of the web site that is input in textbox?


Hi Experts.

In the most web sites when you want to register in any web sites, you must provide your information such as First name, last name, email and etc. Then the web site create a confirm link and send it to your mail. If you input your mail correctly, you can check it in your inbox of your mail and click on it to your registration is completed.

In this scenario, the users should input their mails correctly because the web sites will send the confirm link to it. In other words the mail that the users input must be owned of user else if they can't click on the confirm link.

Suppose you want the users input their web sites instead of their emails address in your web site, Now How can you check the user is owned of the web site that is input in the textbox?

I hope you understand my question else if tell me to describe it more.

With Regards. Mojtaba

How to check if DataTable row is empty



Im using "string user = Database.GetMostRecentReply(id).Rows[0][2].ToString();" to get the username from the most recent reply in my forum.

But how do I check if the row is empty? Im using a try catch at the moment, but there must be a better way to do this.


Check for empty array?


How do i check for empty array?


If I write

If Not ls_filename.Length = 0 then


End If


I get object refernce set to null error

How To Check a Textbox Has Changed in a Formview


Hi all,

How do I check if a textbox in a formview has changed when I click "Update" (in Edit mode)? TIA. I use VS2008 and Framework 3.5.


Check Empty WebPart Using JQuery


Hi All,

Is it possible to identify a empty webpart in the page?

For e.g, we have an annoucement webPart that has no item, The webpart will display an default OOB Message.

Our Requriement is to identify those empty webpart and hide them. Whether this is possible using JQuery/ Javascript?

Note: Solution should in either in JQuery or Javascript or any those OOB option. We should not do any Coding?

Please let me know whether this is possible?


Ganesh Moorthy S

Check if all members of MeasureGroupMeasures are empty

Is there a way to check if all members of MeasureGroupMeasures are empty in the MDX query?

Javier Guillen

Check Whether the grid view is empty or not



Hello all Members,

I am new to asp.net.

i don't know where to post this issue.

Problem that i am facing is,

I have a grid view bind with LINQdatasource control & i want to check whether it is empty or not.

How do i do this ?

and also, If it is empty, then i have to enable a button control on my form.

Please help me in this issue.

Thanks in advance.


Using trim to check element is empty in jQuery

Using trim method, one can also check element is empty or not.

reg exp for check input textbox ip address with padded leading zeros


Hi all!

I'm new in this forum...

I want a regexp to check a input textbox with a ip address ipv4 with all the controls for a valid ip address but:

for example: is not correct for me but i want only or ....

is it possible only with regular expressions?



Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

check box control


Hi ,

I have a three check box in my web form ,i need to choose only one check box, if i choose one check box

another 2 check box automatically unchecked

can i use jquery for check box

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend