programatically generated LinkButton within Datagrid header can't call a sub

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dude

    #1

    programatically generated LinkButton within Datagrid header can't call a sub

    I add a link button to the header of my datagrid as follows:
    If e.Item.ItemType = ListItemType.He ader Then
    Dim myLink As New LinkButton()
    myLink.Text = "Add New"
    myLink.Attribut es.Add("runat", "server")
    myLink.Attribut es.Add("id", "btnAddNew" )
    myLink.Attribut es.Add("Command Name", "btnAddNew" )
    myLink.Attribut es.Add("Command Argument", "btnAddNew" )
    e.Item.Cells(2) .Controls.Add(m yLink)
    AddHandler myLink.Click, AddressOf Me.btnAddNew_Cl ick
    End If
    After postback the sub, btnAddNew_Click is not called. I assume this
    is because since the control is created programatically , it needs to
    be recreated on postback by the page_onload. However, at page_onload
    the datagrid is not yet created, so how can I create the LinkButton
    and add it?
    Thanks!
Working...