<asp:Button id="btnClear" OnClick="Clear();"

R

riga

Can I add a call to javascript function from Web Server Control?
Like this:

<asp:Button id="btnClear" OnClick="Clear();".....>
 
K

Ken Cox [Microsoft MVP]

Yes, you can do that but you should add it during the Load event like this:

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
Button1.Attributes.Add _
("onclick", "DoClose();return false;")
End Sub
</script>
<script>
function DoClose()
{
alert('Routine here.');
}
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>

Ken
Microsoft MVP [ASP.NET]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top