VS 2005..Attaching event handlers

Discussion in 'ASP .Net' started by hharry, May 21, 2007.

  1. hharry

    hharry Guest

    Hello All,

    In VS 2003, I was able to add event handlers in the
    InitializeComponent function. In VS 2005, I can no longer see the auto-
    generated code.

    I tried to add the event handler for a button in the Page_Load event,
    bit this did not work.

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    this.SaveBtn.Click += new
    EventHandler(this.SaveChanges);
    }
    }

    Could somebody explain why the event handler doesn't register properly
    when added in Page_Load event and what the correct procedure is for
    adding event handlers in VS 2005 and if there is a way to view the
    auto-generated code in VS 2005 ?


    Thanks in advance!
    hharry, May 21, 2007
    #1
    1. Advertising

  2. hharry

    bruce barker Guest

    in vs2005, the form and the code behind are partial classes that are
    compiled into one class, instead of using class inheritance. because of
    this vs2005 no longer needs the hack of registering its event handles.
    event handlers specified in the codebehind, can be accessed from the
    form specifiation.

    if you want to do your own hookup, it should be done in oninit.

    -- bruce (sqlwork.com)


    hharry wrote:
    > Hello All,
    >
    > In VS 2003, I was able to add event handlers in the
    > InitializeComponent function. In VS 2005, I can no longer see the auto-
    > generated code.
    >
    > I tried to add the event handler for a button in the Page_Load event,
    > bit this did not work.
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > if (!Page.IsPostBack)
    > {
    > this.SaveBtn.Click += new
    > EventHandler(this.SaveChanges);
    > }
    > }
    >
    > Could somebody explain why the event handler doesn't register properly
    > when added in Page_Load event and what the correct procedure is for
    > adding event handlers in VS 2005 and if there is a way to view the
    > auto-generated code in VS 2005 ?
    >
    >
    > Thanks in advance!
    >
    bruce barker, May 21, 2007
    #2
    1. Advertising

  3. hharry

    bruce barker Guest

    also i noticed you don't add the event on postback, which is the only
    time it would occur.

    -- bruce (sqlwork.com)

    bruce barker wrote:
    > in vs2005, the form and the code behind are partial classes that are
    > compiled into one class, instead of using class inheritance. because of
    > this vs2005 no longer needs the hack of registering its event handles.
    > event handlers specified in the codebehind, can be accessed from the
    > form specifiation.
    >
    > if you want to do your own hookup, it should be done in oninit.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > hharry wrote:
    >> Hello All,
    >>
    >> In VS 2003, I was able to add event handlers in the
    >> InitializeComponent function. In VS 2005, I can no longer see the auto-
    >> generated code.
    >>
    >> I tried to add the event handler for a button in the Page_Load event,
    >> bit this did not work.
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >> {
    >> if (!Page.IsPostBack)
    >> {
    >> this.SaveBtn.Click += new
    >> EventHandler(this.SaveChanges);
    >> }
    >> }
    >>
    >> Could somebody explain why the event handler doesn't register properly
    >> when added in Page_Load event and what the correct procedure is for
    >> adding event handlers in VS 2005 and if there is a way to view the
    >> auto-generated code in VS 2005 ?
    >>
    >>
    >> Thanks in advance!
    >>
    bruce barker, May 21, 2007
    #3
    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. Cowboy \(Gregory A. Beamer\)

    Attaching to event in container object

    Cowboy \(Gregory A. Beamer\), Oct 24, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    350
    Cowboy \(Gregory A. Beamer\)
    Oct 28, 2003
  2. Loane Sharp
    Replies:
    2
    Views:
    675
    Loane Sharp
    Oct 17, 2005
  3. Dood
    Replies:
    1
    Views:
    612
  4. Greg P
    Replies:
    4
    Views:
    334
    Greg P
    Mar 6, 2006
  5. yawnmoth
    Replies:
    2
    Views:
    169
    yawnmoth
    Dec 24, 2005
Loading...

Share This Page