how to call a javascript function using asp.net?
10,210
Use Button.OnClientClick instead on onclick
to register client side javascript event and assign some id to button. The onclick
is used to register server side event.
<asp:Button id="yourButtonID" runat="server" OnClientClick="objects();" />
Author by
user2147280
Updated on June 04, 2022Comments
-
user2147280 almost 2 years
This is what i m trying. calling the function of the inline js. but i didn't working.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="javascript_Tutorials.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>javaScript Tutorials</title> <script type="text/javascript" language="javascript"> function objects() { alert("Well come"); } </script> </head> <body> <form runat="server" id="myform"> <asp:Button onclick="<% objects(); %>" runat="server" /> </form> </body> </html>
and have the following error:
CS1061: 'ASP.webform1_aspx' does not contain a definition for 'objects' and no extension method 'objects' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)