How to Raise Event dynamically?

Discussion in 'ASP .Net Building Controls' started by TamaHina, Oct 9, 2003.

  1. TamaHina

    TamaHina Guest

    I'm trying to create a LinkButton in program code and
    raise click event to a function.

    Here is the code:
    Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack Then
    Dim temp As LinkButton
    temp = New LinkButton
    temp.Text = "Click me"
    AddHandler temp.Click, AddressOf temp_click
    PlaceHolder1.Controls.Add(temp)
    End If
    End Sub

    Private Sub temp_click(ByVal sender As System.Object,_
    ByVal e As System.EventArgs)
    TextBox1.Text = "You clicked me"
    End Sub

    However, the program does not go to temp_click.
    Why? Anyone can tell me?

    Thank you
    TamaHina, Oct 9, 2003
    #1
    1. Advertising

  2. "TamaHina" <> wrote in message
    news:263ed01c38e6a$206e6850$...
    > I'm trying to create a LinkButton in program code and
    > raise click event to a function.
    >
    > Here is the code:
    > Private Sub Page_Load(ByVal sender As System.Object, _
    > ByVal e As System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > If Not IsPostBack Then
    > Dim temp As LinkButton
    > temp = New LinkButton
    > temp.Text = "Click me"
    > AddHandler temp.Click, AddressOf temp_click
    > PlaceHolder1.Controls.Add(temp)
    > End If
    > End Sub
    >
    > Private Sub temp_click(ByVal sender As System.Object,_
    > ByVal e As System.EventArgs)
    > TextBox1.Text = "You clicked me"
    > End Sub
    >
    > However, the program does not go to temp_click.
    > Why? Anyone can tell me?


    Assuming you mean that the program doesn't go to temp_click when you click
    on the LinkButton, the answer is because you need to add dynamic controls
    both on PostBack and non-PostBack requests.
    --
    John Saunders
    Internet Engineer
    John Saunders, Oct 9, 2003
    #2
    1. Advertising

  3. O, I see
    Thank you very much

    "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    news:u4Vl%...
    > "TamaHina" <> wrote in message
    > news:263ed01c38e6a$206e6850$...
    > > I'm trying to create a LinkButton in program code and
    > > raise click event to a function.
    > >
    > > Here is the code:
    > > Private Sub Page_Load(ByVal sender As System.Object, _
    > > ByVal e As System.EventArgs) Handles MyBase.Load
    > > 'Put user code to initialize the page here
    > > If Not IsPostBack Then
    > > Dim temp As LinkButton
    > > temp = New LinkButton
    > > temp.Text = "Click me"
    > > AddHandler temp.Click, AddressOf temp_click
    > > PlaceHolder1.Controls.Add(temp)
    > > End If
    > > End Sub
    > >
    > > Private Sub temp_click(ByVal sender As System.Object,_
    > > ByVal e As System.EventArgs)
    > > TextBox1.Text = "You clicked me"
    > > End Sub
    > >
    > > However, the program does not go to temp_click.
    > > Why? Anyone can tell me?

    >
    > Assuming you mean that the program doesn't go to temp_click when you click
    > on the LinkButton, the answer is because you need to add dynamic controls
    > both on PostBack and non-PostBack requests.
    > --
    > John Saunders
    > Internet Engineer
    >
    >
    >
    TamaHina@Notebook, Oct 9, 2003
    #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. Thanh Nguyen
    Replies:
    0
    Views:
    430
    Thanh Nguyen
    Apr 1, 2004
  2. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    394
    Gabriel Genellina
    Feb 5, 2007
  3. ernest
    Replies:
    2
    Views:
    269
    Roy Smith
    Nov 14, 2010
  4. Jack Bates
    Replies:
    0
    Views:
    262
    Jack Bates
    May 2, 2011
  5. bvdp

    Raise X or Raise X()?

    bvdp, Mar 11, 2012, in forum: Python
    Replies:
    10
    Views:
    343
    Stefan Behnel
    Mar 12, 2012
Loading...

Share This Page