event

Discussion in 'ASP .Net' started by Tony Johansson, Jan 11, 2010.

  1. 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
     
    Tony Johansson, Jan 11, 2010
    #1
    1. Advertising

  2. "Tony Johansson" <> wrote in
    news:t%H2n.5$:

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Jan 11, 2010
    #2
    1. Advertising

  3. "Gregory A. Beamer" <> skrev i meddelandet
    news:Xns9CFD67FD64898gbworld@207.46.248.16...
    > "Tony Johansson" <> wrote in
    > news:t%H2n.5$:
    >
    >> 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
     
    Tony Johansson, Jan 11, 2010
    #3
  4. "Tony Johansson" <> wrote in news:uyI2n.6
    $:

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Jan 11, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    858
    Purvi T
    Oct 19, 2004
  2. Dave Wurtz

    Event On Form From Control Event

    Dave Wurtz, Dec 9, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    356
    Kevin Spencer
    Dec 9, 2003
  3. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,120
    Hans Kesting
    Feb 9, 2004
  4. jorge
    Replies:
    2
    Views:
    1,275
    jorge
    May 26, 2004
  5. Lars Netzel
    Replies:
    3
    Views:
    443
    Greg Burns
    Jul 22, 2004
Loading...

Share This Page