asp.net SS Control Call Client Java Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can an asp.net button that is a server side control call a client side java
function when the button is clicked? If so, please provide
example.....thanks.,
 
A server side button itself cant trigger the javascript, but the client code
it generates can - see the code below

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

Mike Moore said:
Can an asp.net button that is a server side control call a client side java
function when the button is clicked? If so, please provide
example.....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>
 
Back
Top