J
John Timney \(Microsoft MVP\)
Theres an example below, just transfer the server side click event to code
behnd and it should work
--
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
onClientClick() {"
ScriptString += "var retVal = window.confirm('Click OK to continue.
Click Cancel to stop.');"
ScriptString += "window.alert(retVal);"
ScriptString += "if (retVal){"
ScriptString += "window.alert('MVP Code is doing the Postback!');"
ScriptString += "return true;"
ScriptString += "}"
ScriptString += "else"
ScriptString += "{"
ScriptString += "window.alert('MVP Code is NOT Doing the
Postback!');"
ScriptString += "return false;"
ScriptString += "}"
ScriptString += "}<"
scriptString += "/"
scriptString += "script>"
If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
Sub button_onClick( sender as Object,e as EventArgs)
Response.Write("Postback as requested!!!" + DateTime.Now())
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="OK" onserverclick="button_onClick"
onclick="if(!onClientClick()){return false;}"
runat="server">
</form>
</body>
</html>
behnd and it should work
--
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
Cathy said:Has anyone ever made a webform button run an onClick event that is a
Javascript in the HTML code and then after running the script make it go
into the code-behind? An HTML button will run the onClick event but will not
return to the code-behind. I need to get back to the code, which the webform
button will do but I can't make it execute the script.
Any help will be appreciated. Thanks.
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
onClientClick() {"
ScriptString += "var retVal = window.confirm('Click OK to continue.
Click Cancel to stop.');"
ScriptString += "window.alert(retVal);"
ScriptString += "if (retVal){"
ScriptString += "window.alert('MVP Code is doing the Postback!');"
ScriptString += "return true;"
ScriptString += "}"
ScriptString += "else"
ScriptString += "{"
ScriptString += "window.alert('MVP Code is NOT Doing the
Postback!');"
ScriptString += "return false;"
ScriptString += "}"
ScriptString += "}<"
scriptString += "/"
scriptString += "script>"
If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
Sub button_onClick( sender as Object,e as EventArgs)
Response.Write("Postback as requested!!!" + DateTime.Now())
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="OK" onserverclick="button_onClick"
onclick="if(!onClientClick()){return false;}"
runat="server">
</form>
</body>
</html>