Dynamic linkbutton event doesn't fire

Discussion in 'ASP .Net' started by =?Utf-8?B?aG4=?=, Nov 18, 2004.

  1. Hi,

    I have linkbuttons created dynamically and they display fine on the web
    page. However, when I click on the those link buttons, the event doesn't fire.

    Please tell me what's wrong with the following code. Thanks.

    Dim lbtnQuestion As LinkButton = New LinkButton
    lbtnQuestion.Text = "Question " & (j + 1).ToString()

    lbtnQuestion.CommandArgument = j
    AddHandler lbtnQuestion.Command, AddressOf lbtnQuestion_Click

    ........................................................................................
    Private Sub lbtnQuestion_Click(ByVal sender As Object, ByVal e As
    CommandEventArgs)

    Response.Write("Hey")

    End Sub
     
    =?Utf-8?B?aG4=?=, Nov 18, 2004
    #1
    1. Advertising

  2. I tested ur code.
    It works for me !!

    post the complete code, see if u are checking ispostback ??
    Because dyanmic controls needs to created on load everytime.


    "hn" wrote:

    > Hi,
    >
    > I have linkbuttons created dynamically and they display fine on the web
    > page. However, when I click on the those link buttons, the event doesn't fire.
    >
    > Please tell me what's wrong with the following code. Thanks.
    >
    > Dim lbtnQuestion As LinkButton = New LinkButton
    > lbtnQuestion.Text = "Question " & (j + 1).ToString()
    >
    > lbtnQuestion.CommandArgument = j
    > AddHandler lbtnQuestion.Command, AddressOf lbtnQuestion_Click
    >
    > .......................................................................................
    > Private Sub lbtnQuestion_Click(ByVal sender As Object, ByVal e As
    > CommandEventArgs)
    >
    > Response.Write("Hey")
    >
    > End Sub
     
    =?Utf-8?B?dmluYXk=?=, Nov 18, 2004
    #2
    1. Advertising

  3. Hi vinay,

    Thank you for replying.

    I have these linkbuttons created on certain occasions only, not always, so I
    can't have them in ispostback or init. In most cases when the page is
    postback, it should display something else, Only when this particular button
    is clicked then the linkbuttons are created. All I want is when one of these
    linkbuttons is clicked on, it redirects to a another page. Hmmm but you're
    right, first comes the postback then comes the event, and the linkbutton is
    gone during postback. I don't know how to deal with this.

    "vinay" wrote:

    > I tested ur code.
    > It works for me !!
    >
    > post the complete code, see if u are checking ispostback ??
    > Because dyanmic controls needs to created on load everytime.
    >
    >
    > "hn" wrote:
    >
    > > Hi,
    > >
    > > I have linkbuttons created dynamically and they display fine on the web
    > > page. However, when I click on the those link buttons, the event doesn't fire.
    > >
    > > Please tell me what's wrong with the following code. Thanks.
    > >
    > > Dim lbtnQuestion As LinkButton = New LinkButton
    > > lbtnQuestion.Text = "Question " & (j + 1).ToString()
    > >
    > > lbtnQuestion.CommandArgument = j
    > > AddHandler lbtnQuestion.Command, AddressOf lbtnQuestion_Click
    > >
    > > .......................................................................................
    > > Private Sub lbtnQuestion_Click(ByVal sender As Object, ByVal e As
    > > CommandEventArgs)
    > >
    > > Response.Write("Hey")
    > >
    > > End Sub
     
    =?Utf-8?B?aG4=?=, Nov 19, 2004
    #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. Sathyaish
    Replies:
    3
    Views:
    3,131
    Sathyaish
    Sep 8, 2005
  2. Replies:
    4
    Views:
    544
  3. Replies:
    0
    Views:
    728
  4. Andy Fish

    load event doesn't fire unless init event is present

    Andy Fish, Jun 28, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    269
    Jonathan Mast
    Jul 7, 2005
  5. Waldy

    LinkButton Click Event does not fire

    Waldy, Jan 2, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    217
    Waldy
    Jan 2, 2008
Loading...

Share This Page