Solved

client side validation

Posted on 2004-09-06
5
239 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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