static public string DropDownListSelectChangeConfirmScript(string dropDownListId,string message)
{
string script = " <script> \n"
+" var fooIndex; \n"
+" function saveIndexes() \n"
+" { \n"
+" fooIndex = document.all['"+dropDownListId+"'].selectedIndex; \n"
+" } \n"
+" function resetIndexes() \n"
+" { \n"
+" document.all['"+dropDownListId+"'].selectedIndex = fooIndex; \n"
+" } \n"
+" function areYouSure() \n"
+" { \n"
+" if( !confirm('"+message+"')) \n"
+" { \n"
+" resetIndexes(); \n"
+" return false; \n"
+" } \n"
+" else \n"
+" { \n"
+" document.all['"+dropDownListId+"'].detachEvent('onchange', areYouSure); \n"
+" return true; \n"
+" } \n"
+" } \n"
+" saveIndexes(); \n"
+" document.all['"+dropDownListId+"'].attachEvent('onchange', areYouSure); "
+"</script>\n";
return script;
}
private void RegisterClientScript(string dropDownListClientId)
{
string script = DropDownListSelectChangeConfirmScript(
dropDownListClientId,
"Are you sure?"
);
if(!IsStartupScriptRegistered("startup"))
{
RegisterStartupScript("startup",script);
}
}
{
string script = " <script> \n"
+" var fooIndex; \n"
+" function saveIndexes() \n"
+" { \n"
+" fooIndex = document.all['"+dropDownListId+"'].selectedIndex; \n"
+" } \n"
+" function resetIndexes() \n"
+" { \n"
+" document.all['"+dropDownListId+"'].selectedIndex = fooIndex; \n"
+" } \n"
+" function areYouSure() \n"
+" { \n"
+" if( !confirm('"+message+"')) \n"
+" { \n"
+" resetIndexes(); \n"
+" return false; \n"
+" } \n"
+" else \n"
+" { \n"
+" document.all['"+dropDownListId+"'].detachEvent('onchange', areYouSure); \n"
+" return true; \n"
+" } \n"
+" } \n"
+" saveIndexes(); \n"
+" document.all['"+dropDownListId+"'].attachEvent('onchange', areYouSure); "
+"</script>\n";
return script;
}
private void RegisterClientScript(string dropDownListClientId)
{
string script = DropDownListSelectChangeConfirmScript(
dropDownListClientId,
"Are you sure?"
);
if(!IsStartupScriptRegistered("startup"))
{
RegisterStartupScript("startup",script);
}
}