• 0

[ASP.NET] writing an event


Question

I'm receiving this error with the code provided.

Compiler Error Message: BC30456: 'Click' is not a member of 'ASP.learning_survey_aspx'.

Source Error:

Line 40: <!-- Display confirmation button -->

Line 41: <p>

Line 42: <button id="confirmButton" OnServerClick="Click"

Line 43: runat="server">Confirm</button>

 &lt;!-- Display confirmation button --&gt;
	 &lt;p&gt;
		&lt;button id="confirmButton" OnServerClick="Click"
		   runat="server"&gt;Confirm&lt;/button&gt; 



&lt;script runat="server"&gt;
Sub submit(Source As Object, e As EventArgs)
	confirmation.Text="Confirmed"
End Sub	 
&lt;/script&gt;

&lt;form runat="server"&gt;
&lt;asp:Button id="confirmation" Text="Confirm" runat="server"
OnServerClick="Click" /&gt;
&lt;/form&gt;
&lt;/p&gt;

I dont understand the error.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

It's expecting a method that has the name "Click", but your one has the name "submit", make the following change:

Sub Click(Sender as Object, e As EventArgs)
	confirmation.Text = "Confirmed"
End Sub

Link to comment
Share on other sites

  • 0
It's expecting a method that has the name "Click", but your one has the name "submit", make the following change:

Sub Click(Sender as Object, e As EventArgs)  
	confirmation.Text = "Confirmed"
End Sub

try this:

On front end remove the on server click.

on back end:

Protected Sub Confirmation(ByVal sender As Object, ByVal e As System.EventArgs) Handles confirmation.Click
		confirmation.Text = "Confirmed"
	End Sub

Edited by Rohdekill
Link to comment
Share on other sites

  • 0

Now I get this error.

Compiler Error Message: BC30451: Name 'confirmation' is not declared.

Source Error:

Line 47: <script runat="server">

Line 48: Sub Click(Sender As Object, e As EventArgs)

Line 49: confirmation.Text= "Confirmed"

Line 50: End Sub

Line 51: </script>

Link to comment
Share on other sites

  • 0
Now I get this error.

You're missing a server control with the ID of 'confirmation'. (ex. <asp:Label id="confirmation" runat="server"/>). If you have it on the page and you're using Visual Studio, open up your page in html view, switch to design view, and then switch it back to html view. Sometimes Visual Studio fails to write declarations in the partial class.

Link to comment
Share on other sites

  • 0

?Here's my code, in bold is where the error is, but I can't figure it out (confirmation.Text. I tried vs2008's suggestions but didn't work.

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
 &lt;head&gt;
   &lt;title&gt;Using ASP.NET HTML Server Controls&lt;/title&gt;
   &lt;!-- code will go here --&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;form runat="server"&gt;
	 &lt;h2&gt;Take the Survey!&lt;/h2&gt;
	 &lt;!-- Display user name --&gt;
	 &lt;p&gt;
	   Name:&lt;br /&gt;
	   &lt;input type="text" id="name" runat="server" /&gt;
	 &lt;/p&gt;
	 &lt;!-- Display email --&gt;
	 &lt;p&gt;
	   Email:&lt;br /&gt;
	   &lt;input type="text" id="email" runat="server" /&gt;
	 &lt;/p&gt;
	 &lt;!-- Display technology options --&gt;
	 &lt;p&gt;
	   Which server technologies do you use?&lt;br /&gt;
	   &lt;select id="serverModel" runat="server" multiple="true"&gt;
		 &lt;option&gt;ASP.NET&lt;/option&gt;
		 &lt;option&gt;PHP&lt;/option&gt;
		 &lt;option&gt;JSP&lt;/option&gt;
		 &lt;option&gt;CGI&lt;/option&gt;
		 &lt;option&gt;ColdFusion&lt;/option&gt;
	   &lt;/select&gt;
	 &lt;/p&gt;
	 &lt;!-- Display .NET preference options --&gt;
	 &lt;p&gt;
	   Do you like .NET so far?&lt;br /&gt;
	   &lt;select id="likeDotNet/option&gt;
	   &lt;/select&gt;
	 &lt;/p&gt;
	 &lt;!-- Display confirmation button --&gt;
	 &lt;p&gt;
		&lt;button id="confirmButton" OnServerClick="Click"
		   runat="server"&gt;Confirm&lt;/button&gt; 

		&lt;script runat="server"&gt;
			Sub Click(ByVal Source As Object, ByVal e As EventArgs)
				[b]confirmation.Text[/b] = "Confirmed"
			End Sub
		&lt;/script&gt;

&lt;/p&gt;


	 &lt;!-- Confirmation label --&gt;
	 &lt;p&gt;
	   &lt;asp:Label id="feedbacklabel" runat="server" /&gt;
	 &lt;/p&gt;

&lt;/form&gt;
   &lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;

Link to comment
Share on other sites

  • 0

As sbauer has said, you don't actually have a control with that Id, so make this change:

		&lt;script runat="server"&gt;
			Sub Click(ByVal Source As Object, ByVal e As EventArgs)
				feedbacklabel.Text = "Confirmed"
			End Sub
		&lt;/script&gt;

Also, I noticed this:

	   &lt;select id="likeDotNet/option&gt;
	   &lt;/select&gt;

Which is sementically incorrect, and will no doubt cause the browser to mis-render your page.

Link to comment
Share on other sites

  • 0

ok, thanks. I dont get an error anymore. But why the Confirm button is not showing?

Also, I noticed this:

	   &lt;select id="likeDotNet/option&gt;
	   &lt;/select&gt;

Which is sementically incorrect, and will no doubt cause the browser to mis-render your page.

Then what's correct, i didn't do any changes to this?

Link to comment
Share on other sites

  • 0

&lt;select id="likeDotNet" runat="server"&gt;
	&lt;option value="1"&gt;Yes&lt;/option&gt;
	&lt;option value="0"&gt;No&lt;/option&gt;
&lt;/select&gt;

That perhaps?

As for the button, html looks alright now, maybe you are hiding it in CSS? Have you got this public anywhere we can check?

Edit: It might not be visible because of the above issue with your html. Fix that and check again.

Link to comment
Share on other sites

  • 0
&lt;select id="likeDotNet" runat="server"&gt;
	&lt;option value="1"&gt;Yes&lt;/option&gt;
	&lt;option value="0"&gt;No&lt;/option&gt;
&lt;/select&gt;

That perhaps?

As for the button, html looks alright now, maybe you are hiding it in CSS? Have you got this public anywhere we can check?

Edit: It might not be visible because of the above issue with your html. Fix that and check again.

Yeah, I'm sure that's what's causing it not to be displayed. I don't see anything else.

Also, ultimate, it's not good practice to have your server-side script sitting in the middle of your html. Put it in a position that allows it to stand it (top of the page before your HTML, for example).

Link to comment
Share on other sites

  • 0
&lt;select id="likeDotNet" runat="server"&gt;
	&lt;option value="1"&gt;Yes&lt;/option&gt;
	&lt;option value="0"&gt;No&lt;/option&gt;
&lt;/select&gt;

That perhaps?

As for the button, html looks alright now, maybe you are hiding it in CSS? Have you got this public anywhere we can check?

Edit: It might not be visible because of the above issue with your html. Fix that and check again.

This fixed the problem, thanks.

Yeah, I'm sure that's what's causing it not to be displayed. I don't see anything else.

Also, ultimate, it's not good practice to have your server-side script sitting in the middle of your html. Put it in a position that allows it to stand it (top of the page before your HTML, for example).

Thanks for the tip.

Thank you guys for your help. :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.