Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to javascript. I got the below error while running the code.

ERROR:
Error 1 'ASP.default_aspx' does not contain a definition for 'alertMsg' and no extension method 'alertMsg' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) D:\Asp.net\AutoClickButton\Default.aspx 1 1 D:\Asp.net\AutoClickButton\
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Untitled Page</title>
<script language="javascript" type="text/javascript">
function Hello()
{
alert("Hello");
}
</script>   


</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Hello()" />
       
    </div>
    </form>
</body>
</html>
Posted
Updated 30-Mar-12 1:56am
v3
Comments
ZurdoDev 30-Mar-12 7:56am    
Add tags.
ZurdoDev 30-Mar-12 7:56am    
Look for wherever you have alertMsg. You have it defined somewhere that is not correct.
bbirajdar 30-Mar-12 8:03am    
wrong code pasted
_Zorro_ 30-Mar-12 8:44am    
Indeed
Anderson8055 20-Apr-12 6:37am    
I know that the above code is wrong. For asking what have to be done only i have pasted it

ASP.NET controls talk to the "code behind", not to the scripting on the aspx page.

Either use a regular HTML text control, or try OnClientClick() event of the Button.
 
Share this answer
 
C#
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 id="Head1"  runat="server">
    <title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function Hello()
{
alert("Hello");
}
</script>


</head>
<body>
    <form id="form1"  runat="server">
    <div>

        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>

    </div>
    </form>
</body>
</html>



protected void Button1_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "Hello();", true);
    }
 
Share this answer
 
v2
Comments
fjdiewornncalwe 30-Mar-12 10:13am    
Bad form to use an entire page postback to do something that can be done from a client side javascript handler alone.
Anderson8055 2-Apr-12 5:47am    
The solution is so cool!! I got the output!Thanks!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900