Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > event

Reply
Thread Tools

event

 
 
Tony Johansson
Guest
Posts: n/a
 
      01-11-2010
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


 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      01-11-2010
"Tony Johansson" <(E-Mail Removed)> wrote in
news:t%H2n.5$(E-Mail Removed):

> 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! |
*******************************************
 
Reply With Quote
 
 
 
 
Tony Johansson
Guest
Posts: n/a
 
      01-11-2010
"Gregory A. Beamer" <(E-Mail Removed)> skrev i meddelandet
news:Xns9CFD67FD64898gbworld@207.46.248.16...
> "Tony Johansson" <(E-Mail Removed)> wrote in
> news:t%H2n.5$(E-Mail Removed):
>
>> 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! |
> *******************************************


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


 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      01-11-2010
"Tony Johansson" <(E-Mail Removed)> wrote in news:uyI2n.6
$(E-Mail Removed):

> 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! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Catching a RequiredFiled Validator event in PageLoad or some other event? Lars Netzel ASP .Net 3 07-22-2004 10:48 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
PreRender Event occurs immediatley after Load event =?Utf-8?B?QWxpcmV6YSBaaWFp?= ASP .Net 1 02-09-2004 10:19 AM
Event On Form From Control Event Dave Wurtz ASP .Net 1 12-09-2003 10:37 PM



Advertisments