Hi, I am using java script in asp.net 2.0. I have button on form . when i click button it shud execute java script (showAlert() function) . So I added Button1.Attributes.Add("onclick","showAlert()"); <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="checkjs.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script type ="text/Jscript"> function showAlert() { alert('ALERT ALERT!!'); } </script> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 144px" runat="server" Text="Button" onclick="showAlert()"></asp:Button> </form> </body> </HTML> but I am getting this error webform does not contain a definition for 'showAlert'
I'm not sure, but maybe replacing <script type ="text/Jscript"> with <script language="javascript"> Or maybe, replacing onclick="showAlert()" with onclick="javascript:showAlert()"
I tried replacing onclick="showAlert()" with onclick="javascript:showAlert()" still same error Thanks for reply
I am curious. I've never coded in .net b4 so please excuse my ignorance, but where does the showAlert() function exist? Is it in "checkjs.WebForm1"?
Hi actually I got solution I have to add my alert function in PageLoad method since I am working on asp.net 1.1 I am not allowed to use script in html file along with server control. private void Page_Load(object sender, System.EventArgs e) { Page.RegisterStartupScript("MyScript", "<script language=javascript>" + "function AlertHello() { alert('Hello ASP.NET'); }</script>"); Button1.Attributes.Add("onclick","AlertHello()"); }