Drop down list clientside validation before postback

Posted on 2006-05-31
Last Modified: 2006-11-18

I have a drop down list and when the value changes, a postback occurs.

I want to show a popup warning when the value is changed to warn the user about making the change, giving the user the ability to cancel. I am using the Javascrpt confirm function to warn the user.

The pop up appears, but the postback is not happening. If I add change this to work from a buttons onClick event, it works okay.

The code:

Code behind - In the page load:
ddlPersonTypes.Attributes.Add("onChange", "return changePersonType();")

Javascript in the HMTL:

function changePersonType()
      // Ask user to confirm.
      var retValue = confirm("Changing the user type may result in loss of existing data.\n\nContinue?");
      // Check users response.
      if (retValue == true)
            return true;
            return false;

Please help!!!
Question by:kgjertsen
    LVL 11

    Accepted Solution


    I believe this will help you:


    LVL 20

    Expert Comment


    ddlPersonTypes.Attributes.Add("onChange", "return confirm('Changing the user type may result in loss of existing data.\n\nContinue?');")
    LVL 2

    Author Comment

    REA_ANDREW: I wanted to do some other coding if cancel was selected (reset the entry), so I wanted to keep it in a function.

    Saleek was the first to give an answer that helped so he gets the points.

    Saleek: Many thanks.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 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

    14 Experts available now in Live!

    Get 1:1 Help Now