ASP.Net Newbie question

B

BigOldH

Hi

I have been working through some basic samples and there is a problem with a
call to a button click

I am using Visual Studio 2008 and have placed a text box, a label and button
on a page - sample code here

<script language="C#" runat="server">
private void Button1_Click(object sender, System.EventArgs e)
{
lblSample.Text = txtSample.Text;
}
</script>

<form id="Form1" method="post" runat="server">
<P> <asp:Label id="lblSample" runat="server"
Width="208px">Label</asp:Label></P>
<P> <asp:Label id="Label1" runat="server" Width="104px">Enter Text
Here:</asp:Label>
<asp:TextBox id="txtSample" runat="server"></asp:TextBox></P>
<P> <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button> </P>
</form>

this submits the form but does not update the label.Text.

setting a break point in the button click never gets called

If however I transfer the code to the Page Load event it does get called.

Given that this is asample of a similar type in both a book and from a
seperate online tutorial it seems that I am doing something basically wrong.

TIA
H
 
P

parez

you mite have not added the function to the click event.

try adding the following line to your form_load

Button1.Click+=new EventHandler( Button1_Click);
 
M

Mudassar Hassan

Double click on the button and see cursor, weather it goes to the
"Button1_Click" Handler method or it creates a new handler named
"Button1_Click_1"; if it creates a new handler then place code in the new
handler or simply remove the previous handler and then double click on the
button and paste code there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top