2.0: asp:Button click at server

R

R.A.M.

Hello,
I have very simple problem which I present here second time, because I
haven't got a solution.
I need to process asp:Button click at server. I have written (my
experience is little) in .aspx:

<asp:Button ID="GoTo" runat="server"
Text="Go To" OnClick="GoTo_Click" />

and in .aspx.cs I have written with Visual Studio:
....
protected void Page_Load(object sender, EventArgs e)
{
GoTo.Click += new EventHandler(this.GoTo_Click);
}
public void GoTo_Click(object sender, EventArgs e)
{
Response.Redirect(...);
}
....

I don't understand why it doesn't work - GoTo_Click is not called.
Could you explain me please what's wrong? (I copied MSDN sample code).
Thank you!!!
/RAM/
 
G

Guest

Hello R.A.M.,

For ASP.NET 2.0 you don't need to explicitly wire the EventHandler for the
button. For 2.0 you only need to to declare the attribute in the aspx page:

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

and have the function signature in the code behind file:

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "I've been clicked";
}

Under 2.0 the first time the page is compiled for use the event is
dynamically bound to the event handler. You don't need to explicity add the
event handler like you (or VS 2003) did under 1.1.
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top