You must Sign In to post a response.
  • Category: ASP.NET

    Check Textbox for null

    I have a text box which is modified into a rich text editor using a free editor...

    I have to insert the details which is keyed in the Textbox with multiline mode by the user and it has to be stored in the database. The inserting details to the database is working fine... My problem is I have to check the Textbox for null .. that means if the user is not entering anything in the Textbox and pressing enter... a null value is getting inserted in the table column.

    I am calling the method which inserts the details into the DB in the button click event of the submit button.I tried checking the Textbox against the null value like below

    if(txtRichText.Text != null)
    {
    InsertComments(clientVO);
    }

    but it is not working fine ...

    I want the InsertComments method to be called only when the user has entered some text in the multiline textbox.

    Please help me with ideas.

    Regards
    Srividhya
  • #594670
    Hi,

    Use the below code,

    if(txtRichText.Text.Trim() !="")
    {
    InsertComments(clientVO);
    }


    It will work...

    Thanks,
    Senthilnathan

  • #594672
    Hi
    you can try like this
    string tName = Convert.ToString(txtname.Text);
    if(tName == null)
    {
    your code
    }

    Thanks & Regards
    Santosh Singh
    Microsoft Certified Technology Specialist.
    Email:santosh0683@gmail.com
    http://varanasitravel.in

    "In order to succeed you must fail, so that you know what not to do the next time."

  • #594676
    Senthil and Santosh

    Thanks a loot...

    I dont know why did I ask this question... it is simple... we can also do it by

    if(!string.IsNullorEmpty(Textbox1.Text)
    {
    InsertComments();
    }

    It worked fine..

    Regards
    Srividhya

  • #594678
    Fine.
    Thanks,
    Senthilnathan

  • #594682
    Hi,

    You could even add Required Field validator to be associated with the text box to check for user entered any data in the text box.

    Regards
    Guru

  • #594696
    try this code

    if(txtRichText.Text != "")
    {
    InsertComments(clientVO);
    }


    hope this will help you

  • #594703
    hi
    dim len as Integer=0
    len=txt1.length
    if len = 0 then
    'error mess
    else
    'update the db
    end if

  • #594719
    Hi,
    If the user had pressed enter without entering any text, then
    the null space will be inserted in the text box. To validate this
    you need to call the Trim() in the textbox.

    if(txtRichText.Text.Trim() != " ")
    {
    InsertComments(clientVO);
    }

    It is not matter that you are asking simple questions, the acquiring of the knowledge from the forum is very important. Please feel free
    to ask questions.

    All is well.
    Thanks,
    Dharma
    Editor,Mentor,MVM
    Try and fail but don't fail and try


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.