Solved

client side validation

Posted on 2004-09-06
5
237 Views
Last Modified: 2010-04-23

Hi
 
      I have a dropdown list on the form and have to validate it using client side validation. If the user does not select any value from dropdown list, error message should pop up. can anybody give code for this validation using javascript in vb.net

thanks

sandeep
0
Comment
Question by:sandeep437
  • 2
5 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 11992796
This should be on the ASP.NET forum, but I'll help out here:

If you have a button or something that is clicked to post the page back to the server, have it check the dropdown list like this: (ddl is the name I'll use for the list).

if (ddl.SelectedIndex == 0)
{
     // the following is basic javascript to show a message.
     string jsMsg = "<script language=\"javascript\">alert('You need to make a selection...');</script>"
     Response.Write(jsMsg);
}
else
{
     // do whatever with the drop down selection.
}

The alert() function in javascript is the browser equivalent of MsgBox().

John

John
0
 

Author Comment

by:sandeep437
ID: 11993420
Hi john

    i am looking for code in vb.net  not  c#.net.
i declared a string like this.

dim jsMsg as String  = "<script language=\"javascript\">alert('You need to make a selection...');</script>"
Response.write(jsMsg)

but its showing error as "end of statement expected".

do you know where its going wrong.

thanks

sandeep
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 50 total points
ID: 11993874
The escape sequence of \" will not work in VB.NET (it is a C# thing, sorry about that).  Do this:

dim jsMsg as String  = "<script language='javascript'>alert('You need to make a selection...');</script>"
Response.write(jsMsg)

John
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A short film showing how OnPage and Connectwise integration works.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now