AddHandler VB.NET and ASP.NET

Discussion in 'ASP .Net' started by Landley, Oct 18, 2005.

  1. Landley

    Landley Guest

    Hi,

    I have created a simple Web User Control. It dynamically creates a table.
    With a cell in the table, it creates a Button control set to run at the
    server. I then call AddHandler and handle the Click event from the button
    and raise it as an event within my User Control. This seems to be
    happening, so much as it getting the RaiseEvent line, but it just does not
    raise the event. There are no errors, it just carries on executing.

    Is there an issue with dynamically adding controls to a user control and
    wrapping their events in a single event in a User Control using VB.NET in
    ASP.NET? If not, can someone post a sample on how to do so?

    L.
     
    Landley, Oct 18, 2005
    #1
    1. Advertising

  2. For dynamically created controls consider carefully the page lifecycle.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp

    If you create controls after the initialization stage make sure that you
    recreate them again during the Page_init or at least Page_load otherwise
    their events would be lost. In this simple demo
    http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx I create
    the controls later in the page but persist some indicators that allow me to
    recreate them upon page_load and thereby preserve their event handling.

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Landley" wrote:

    > Hi,
    >
    > I have created a simple Web User Control. It dynamically creates a table.
    > With a cell in the table, it creates a Button control set to run at the
    > server. I then call AddHandler and handle the Click event from the button
    > and raise it as an event within my User Control. This seems to be
    > happening, so much as it getting the RaiseEvent line, but it just does not
    > raise the event. There are no errors, it just carries on executing.
    >
    > Is there an issue with dynamically adding controls to a user control and
    > wrapping their events in a single event in a User Control using VB.NET in
    > ASP.NET? If not, can someone post a sample on how to do so?
    >
    > L.
    >
    >
    >
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Oct 18, 2005
    #2
    1. Advertising

  3. Landley

    Landley Guest

    Thanks, I'll have a look.

    L.

    "Phillip Williams" <> wrote in message
    news:...
    > For dynamically created controls consider carefully the page lifecycle.
    >
    >

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp
    >
    > If you create controls after the initialization stage make sure that you
    > recreate them again during the Page_init or at least Page_load otherwise
    > their events would be lost. In this simple demo
    > http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx I

    create
    > the controls later in the page but persist some indicators that allow me

    to
    > recreate them upon page_load and thereby preserve their event handling.
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Landley" wrote:
    >
    > > Hi,
    > >
    > > I have created a simple Web User Control. It dynamically creates a

    table.
    > > With a cell in the table, it creates a Button control set to run at the
    > > server. I then call AddHandler and handle the Click event from the

    button
    > > and raise it as an event within my User Control. This seems to be
    > > happening, so much as it getting the RaiseEvent line, but it just does

    not
    > > raise the event. There are no errors, it just carries on executing.
    > >
    > > Is there an issue with dynamically adding controls to a user control and
    > > wrapping their events in a single event in a User Control using VB.NET

    in
    > > ASP.NET? If not, can someone post a sample on how to do so?
    > >
    > > L.
    > >
    > >
    > >
     
    Landley, Oct 18, 2005
    #3
  4. Landley

    Landley Guest

    I fixed my issue.

    The ID on the aspx pages was called something totally different to the one
    declared in the aspx.vb file! I know, I know! Basic error!

    Thanks anyway.

    Landers.


    "Landley" <> wrote in message
    news:%...
    > Thanks, I'll have a look.
    >
    > L.
    >
    > "Phillip Williams" <> wrote in message
    > news:...
    > > For dynamically created controls consider carefully the page lifecycle.
    > >
    > >

    >

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp
    > >
    > > If you create controls after the initialization stage make sure that you
    > > recreate them again during the Page_init or at least Page_load otherwise
    > > their events would be lost. In this simple demo
    > > http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx I

    > create
    > > the controls later in the page but persist some indicators that allow me

    > to
    > > recreate them upon page_load and thereby preserve their event handling.
    > >
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "Landley" wrote:
    > >
    > > > Hi,
    > > >
    > > > I have created a simple Web User Control. It dynamically creates a

    > table.
    > > > With a cell in the table, it creates a Button control set to run at

    the
    > > > server. I then call AddHandler and handle the Click event from the

    > button
    > > > and raise it as an event within my User Control. This seems to be
    > > > happening, so much as it getting the RaiseEvent line, but it just does

    > not
    > > > raise the event. There are no errors, it just carries on executing.
    > > >
    > > > Is there an issue with dynamically adding controls to a user control

    and
    > > > wrapping their events in a single event in a User Control using VB.NET

    > in
    > > > ASP.NET? If not, can someone post a sample on how to do so?
    > > >
    > > > L.
    > > >
    > > >
    > > >

    >
    >
     
    Landley, Oct 19, 2005
    #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. Jeffrey A. Voigt

    Help w/AddHandler (Not Firing Off)

    Jeffrey A. Voigt, Aug 10, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    675
    Natty Gur
    Aug 11, 2003
  2. Natty Gur

    Re: Help w/AddHandler (Not Firing Off)

    Natty Gur, Aug 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    Jeff Voigt
    Aug 11, 2003
  3. =?Utf-8?B?Q2FybG8zMDMw?=

    Convert ADDHandler and AddressOf to C#

    =?Utf-8?B?Q2FybG8zMDMw?=, May 4, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    28,885
    =?Utf-8?B?Q2FybG8zMDMw?=
    May 9, 2006
  4. Vassili King
    Replies:
    3
    Views:
    762
    Vassili King
    Jun 21, 2007
  5. Greg

    AddHandler and dynamically generated controls

    Greg, Feb 11, 2008, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    217
Loading...

Share This Page