Drop down list clientside validation before postback

Hi,

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;
      else
            return false;
}

Please help!!!
LVL 2
kgjertsenAsked:
Who is Participating?
 
Ramesh SrinivasTechnical ConsultantCommented:
hi,

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

regards,

KS
0
 
REA_ANDREWCommented:

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

Karl
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.