Click here to Skip to main content
13,197,200 members (55,091 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

I have an dropdownlist with autopostback false.

I have written js code to display confirm message while dropdown value changed.
function ConfirmAbsent(ddlPresence) {
            if (ddlPresence != null) {
                var myValue = ddlPresence.options[ddlPresence.selectedIndex].text;
                var blnAbsent = confirm("This will mark as "+ myValue +". Please confirm clicking OK.");
                if (blnAbsent) {
                    return true;
                else {
                    return false;

And add this attribute to dropdownlist like below

ddlUserPresence.Attributes.Add("onchange", "if (!ConfirmAbsent(" + ddlUserPresence.ClientID
                        + ")) return; else __doPostBack('"
                        + ddlUserPresence.UniqueID + "', '');");

When i click on ok it postback the page working correctly, but when i click on cancel button it is not showing me the previous value instead showing the current value.

So when i click on cancel button it should show me the previous value.Please help.
I have tried hidden field also.But still its not working.
Posted 27-Sep-12 1:12am
akee seth1.6K
Malli_S 27-Sep-12 7:19am
Use 'OnSelectedIndexChanged' instead of 'onchange'.
aspnet_regiis 27-Sep-12 9:45am
He is using javascript.. 'OnSelectedIndexChanged' is a server side event

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you wish to do this solely on the client side with javascript, you'll have to create a temporary placeholder variable in the javascript to hold the current value. When the page loads, set this value to the initial value of the dropdownlist. When someone clicks Cancel on the confirmation, you just have to reset the selected value of the dropdownlist to the temporary placeholder value. When a user accepts confirmation, you just have to update the placeholder to the new value.
akee seth 28-Sep-12 1:14am
I have tried it.But still not working.Its showing undefined value.
Marcus Kramer 28-Sep-12 8:40am
If you have an undefined value, then either you have not set the temporary placeholder value on page load, or there is no value on page load. In either case, when you want to reset the value of the dropdown from the temporary placeholder, you should check if the value is undefined (yourValue == null) and then take action to set the value to an appropriate default value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100