Error 1 'ASP.default_aspx' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\kalpana.kanthasamy\Documents\Visual
Studio 2008\WebSites\WebSite4\Default.aspx 19
I beleive you may did a mistake when adding your page.
when adding a new aspx page you have to uncheck the "Place code in seperate file" checkbox in add new item window as you are embedding your c# code in aspx page itself.
recommand you to delete your existing page and follwo below step,
right click on your project from solution explorer
What is the end result you are looking for after finishing this tutorial?
Looking at the name of your post "javascript along with asp.net" and the tutorial you posted I take it in the long run you are trying to fire a JavaScript function or some sort of JavaScript on button click. If this is the case I guess I should have
left my last post up.
Skipping all the run around and getting stright to the point if you wish to execute the JavaScript Function helloWorld() you can do it when the ASP.NET button is clicked like so:
You can set a JavaScript onclick event as well in your code behind by adding an attribute to Button1 on page load like so which will fire the JavaScript function helloWorld().
callykalpana
Member
7 Points
52 Posts
javascript along with asp.net = beginner needs help
Jan 25, 2013 11:15 AM|LINK
Hi,
I have been trying this code(below) from this site - http://msdn.microsoft.com/en-us/library/aa479011.aspx#aspnet-usingjavascript_topic02 but I kept getting this error
Error 1 'ASP.default_aspx' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\kalpana.kanthasamy\Documents\Visual Studio 2008\WebSites\WebSite4\Default.aspx 19
The code
<%@ Page Language="C#" %> <script runat="server"> void Button1_Click(object sender, EventArgs e) { Response.Write("Postback!"); } </script> <html> <head> </head> <body onload="javascript:document.forms[0]['Button1'].value=Date();"> <form id="Form1" runat="server"> <p> <asp:Button id="Button1" onclick="Button1_Click" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Larger"></asp:Button> </p> </form> </body> </html>g_mani
Contributor
2055 Points
586 Posts
Re: javascript along with asp.net = beginner needs help
Jan 25, 2013 12:02 PM|LINK
your code is perfectly working for me!!
I beleive you may did a mistake when adding your page.
when adding a new aspx page you have to uncheck the "Place code in seperate file" checkbox in add new item window as you are embedding your c# code in aspx page itself.
recommand you to delete your existing page and follwo below step,
Please Mark as Answer If this is helpful.
bbcompent1
All-Star
33873 Points
8776 Posts
Moderator
Re: javascript along with asp.net = beginner needs help
Jan 25, 2013 12:02 PM|LINK
here's one thign you could try, take the
<script runat="server"> void Button1_Click(object sender, EventArgs e) { Response.Write("Postback!"); } </script>and rewrite the void part as:
<script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Response.Write("Postback!"); } </script>CruzerB
Contributor
5399 Points
1098 Posts
Re: javascript along with asp.net = beginner needs help
Jan 25, 2013 12:13 PM|LINK
Hi,
http://msdn.microsoft.com/en-us/library/aa479390.aspx
I think you have to follow this link. The link that you provided is actually for .NET 1.0/1.1 So the code below should works for you.
<%@ Page Language="C#" %> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Response.Write("Postback!"); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Using JavaScript</title> </head> <body onload="javascript:document.forms[0]['Button1'].value=Date();"> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Font-Bold="True" Font-Names="Verdana" Font-Size="Larger" /> </div> </form> </body> </html>My Technical Blog
jprochazka
Contributor
4992 Points
748 Posts
Re: javascript along with asp.net = beginner needs help
Jan 25, 2013 12:21 PM|LINK
What is the end result you are looking for after finishing this tutorial?
Looking at the name of your post "javascript along with asp.net" and the tutorial you posted I take it in the long run you are trying to fire a JavaScript function or some sort of JavaScript on button click. If this is the case I guess I should have left my last post up.
Skipping all the run around and getting stright to the point if you wish to execute the JavaScript Function helloWorld() you can do it when the ASP.NET button is clicked like so:
<html> <head> <script type="text/javascript"> function helloWorld() { alert("Hello world!"); } </script> </head> <body onload="javascript:document.forms[0]['<%= Button1.ClientID %>'].value=Date();"> <form id="Form1" runat="server"> <p> <asp:Button id="Button1" OnClientClick="return helloWorld();" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Larger"></asp:Button> </p> </form> </body> </html>You can set a JavaScript onclick event as well in your code behind by adding an attribute to Button1 on page load like so which will fire the JavaScript function helloWorld().
Button1.Attributes.Add("onclick", "return helloWorld();");callykalpana
Member
7 Points
52 Posts
Re: javascript along with asp.net = beginner needs help
Jan 26, 2013 02:53 AM|LINK
Hi, thanks...for the answer.Yeah I guess the.Net thing was of a different version.it works fine now.