?
Solved

client side validation

Posted on 2004-09-06
5
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 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