event

T

Tony Johansson

Hello!

If you have this simple code in the code behind file.
I just wonder if you ever use this type of coding that is used in win forms
?
helpButton.Click += new System.EventHandler(Button1_Click);

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
helpButton.Text = "HELP";
helpButton.BackColor = Color.LightCoral;

}
protected void Button1_Click(object sender, EventArgs e)
{
helpButton.Text = "You have hit me";
}
}

//Tony
 
G

Gregory A. Beamer

If you have this simple code in the code behind file.
I just wonder if you ever use this type of coding that is used in win
forms ?

yes, but you generally don't realize it, as the designer (.NET 2.0 or
greater) hides the wiring. It is less hidden in VB than C#. But, yes, the
event handlers are wired using delegates, just like win forms.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
T

Tony Johansson

Gregory A. Beamer said:
yes, but you generally don't realize it, as the designer (.NET 2.0 or
greater) hides the wiring. It is less hidden in VB than C#. But, yes, the
event handlers are wired using delegates, just like win forms.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Do you mean that this part
OnClick="Button1_Click"
of the code in default.aspx that can be seen below
is more or less substituting this construction
helpButton.Click += new System.EventHandler(Button1_Click);

%@ 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="helpButton" runat="server" OnClick="Button1_Click"
Style="z-index: 100;
left: 121px; position: absolute; top: 135px" Text="Button" />
</div>
</form>
</body>
</html>

//Tony
 
G

Gregory A. Beamer

Do you mean that this part
OnClick="Button1_Click"
of the code in default.aspx that can be seen below
is more or less substituting this construction
helpButton.Click += new System.EventHandler(Button1_Click);

Yes, and in some instances you can use the actual delegate call, as in the
Windows forms. In fact, if you go back to Framework 1.x, you find:

helpButton.Click += new System.EventHandler(helpButton_Click);

Run Reflector over the compiled website assemblies and you should see this
(will have to check how it does it now, but I am almost 100% confident you
will see the delegate wired up in the compiled code).

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top