• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

Drop down list clientside validation before postback


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!!!
1 Solution
Ramesh SrinivasTechnical ConsultantCommented:

I believe this will help you: http://scottonwriting.net/sowBlog/posts/1489.aspx



ddlPersonTypes.Attributes.Add("onChange", "return confirm('Changing the user type may result in loss of existing data.\n\nContinue?');")
kgjertsenAuthor Commented:
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.


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now