dropdownlist postback
-
I have a dropdownlist with a OnSelectedIndexChange event handler which extract data from the database when index change. But before the OnSelectedIndexChange being raise I need to validate the answer of the user on the Confirm dialog box(javascript) which will be shown if the user change the value of the dropdownlist. The answer on the confirm dialogbox will determine, if the dropdownlist will postback or not. But the problem is either I choose OK or Cancel it always raise the OnSelectedIndexChange on the server side that cause the postback. Here's my question How to prevent the dropdownlist to raise a postback if the selected index are 1,2,3,4,5 or the answer to the confirm dialog is Cancel.
-
I have a dropdownlist with a OnSelectedIndexChange event handler which extract data from the database when index change. But before the OnSelectedIndexChange being raise I need to validate the answer of the user on the Confirm dialog box(javascript) which will be shown if the user change the value of the dropdownlist. The answer on the confirm dialogbox will determine, if the dropdownlist will postback or not. But the problem is either I choose OK or Cancel it always raise the OnSelectedIndexChange on the server side that cause the postback. Here's my question How to prevent the dropdownlist to raise a postback if the selected index are 1,2,3,4,5 or the answer to the confirm dialog is Cancel.
R u returning boolean value from ur function of javascript? If not do one thing return false from ur javascript function when user choose to cancel. Second thing when u call a javascript function on onindexchange client side event of dropdown call it with return statment. e.g. dropdownlist.attributes.add("OnIndexchange","return fnc();"); all the best Happy Programming Manoj Tillu
-
R u returning boolean value from ur function of javascript? If not do one thing return false from ur javascript function when user choose to cancel. Second thing when u call a javascript function on onindexchange client side event of dropdown call it with return statment. e.g. dropdownlist.attributes.add("OnIndexchange","return fnc();"); all the best Happy Programming Manoj Tillu
Yup, I did that but instead of using the OnIndexchange attribute I’ve choose the the OnChange attribute. What is the difference between the two attribute? This code was inside the Page Load Event Handler. This will drop the needed javascript function on page load.
javascript.Append(""); javascript.Append("var dropDownListSelectedIndex = -1;"); javascript.Append("function verify(msg)"); javascript.Append("{"); javascript.Append(" var isOK = confirm(msg);"); javascript.Append(" if (!isOK)"); javascript.Append(" {"); javascript.Append(" obj.selectedIndex = dropDownListSelectedIndex;"); javascript.Append(" }"); javascript.Append(" return isOK;"); javascript.Append("}"); javascript.Append(""); Page.RegisterStartupScript("dropDownListConfirm", javascript.ToString());
Here's the adding of attribute from dropdownlist.
Dropdownlist.Attributes.Add("OnChange", "javascript:verify(this)");
Thanks,