我试图找出how to display confirm box when drop down list's selected indexchanged事件被触发。
通过某个论坛浏览我遇到了以下解决方案,但我不知道如何使用它,因为我在c#中工作。我如何使其工作?我甚至不确定这是否真的是我的问题的解决方案。请帮帮忙。谢谢。
Public Sub ConfirmOnChange()
'Register the script block
If Not IsStartupScriptRegistered("CSP-ddl-onchange") Then
RegisterStartupScript("CSP-ddl-onchange", _
"<script language=""JavaScript"">" & _
"var CSP_savedDDLID = " & _
"document.getElementById('" & _
ddl.ClientID & "').value;" & vbCrLf & _
"function resetDDLIndex() {" & vbCrLf & _
" document.getElementById('" & _
ddl_Status.ClientID & "').value = CSP_savedDDLID;" & _
vbCrLf & _
"}" & vbCrLf & _
"</script>")
End If
Dim msg As String = "'Do you want to change selection?';"
ddl_Status.Attributes("onchange") = _
"if (!confirm('" & msg.Replace("'", "\'") & _
"')) resetDDLIndex(); "
End Sub
答案 0 :(得分:3)
public void ConfirmOnChange()
{
//Register the script block
if(!IsStartupScriptRegistered("CSP-ddl-onchange"))
{
RegisterStartupScript("CSP-ddl-onchange",
"<script language=\"JavaScript\">" +
"var CSP_savedDDLID = " +
"document.getElementById('" +
ddl.ClientID + "').value;" + "\r\n" +
"function resetDDLIndex() {" + "\r\n" +
" document.getElementById('" +
ddl_Status.ClientID + "').value = CSP_savedDDLID;" +
"\r\n" +
"}" + "\r\n" +
"</script>");
}
string msg = "'Do you want to change selection?';";
ddl_Status.Attributes("onchange") = "if (!confirm('" & msg.Replace("'", "\'") +
"')) resetDDLIndex(); ";
}