Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-06-30 : 23:20:00
|
I have a dropDownList set on autopostback in my page. When the user changes the item, I want to display a confirm dialog. If he cancels I want to put back the original item (that s why I have the va SavedTyp)Here is my Sub:Private Sub ResetAccTyp(ByVal drp As DropDownList)If Not Page.IsStartupScriptRegistered("drp-on-change") Then Page.RegisterStartupScript("drp-on-change", "<script language=""JavaScript""> var SavedTyp=document.getElementById('" & drp.ClientID & "').value;" & vbCrLf & "function resetAccTyp(){" & vbCrLf & " document.getElementById('" & drp.ClientID & "').value=SavedTyp;" & vbCrLf & "}" & vbCrLf & "</script>")End Ifdrp.Attributes("onchange") = "if !(confirm('re u sure')) resetAccTyp(); else"End SubThen I call that Sub in the selectedIndexChanged of the dropdownList in my page but it diplayes nothing and the selected index never goes back to its origin.Thanks for your help |
|
fthiemonge
Starting Member
2 Posts |
Posted - 2006-07-20 : 10:25:26
|
I would like to do the same thing. Any luck since your original post? If not, it seems to me you'd need to keep track of the original value of the dropdownlist (perhaps in a viewstate variable) so on postback you know what it was and can set it accordingly (along with keeping track of what was attempted). This way you can manually set the values properly in the code behind. As for why the script is not running, what does the page that is rendered look like? Basically is the javascript in the body (not the head), and is valid, etc? Save off the "view code" version of the page as an HTML page and fudge with it until the javascript runs on page load.Hope this helps,Frank |
 |
|
fthiemonge
Starting Member
2 Posts |
Posted - 2006-07-24 : 17:43:33
|
In case anyone browses and finds this, I solved it by keeping track of before and after values in the viewstate, a confirm box sent the first time using something like this:Page.RegisterStartupScript("PeriodConfirm", "<script language=\"javascript\">\r\n" + " if (confirm(unescape(\"Changes%20made%20to%20this%20page%20will%20not%20be%20saved.\\r\\n\\r\\nPress%20OK%20to%20continue,%20or%20Cancel%20to%20stay%20on%20the%20current%20page.\"))) {\r\n" +" __doPostBack('ddlMyBox','confirmed');\r\n" +" }\r\n" +"</script>");then check Request["__EVENTARGUMENT"] for value of "confirmed" on postback (for Request["__EVENTTARGET"] == "ddlMyBox").It took a little more tweaking to get the selected indexes to work properly, but that's the bulk of it.Cheers,Frank |
 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-09-13 : 06:43:29
|
Cool man. didn t try to make that code work since then. I ll use yours in the future.Take care |
 |
|
|
|
|
|
|