Dynamic button event won't fire
Hi All,
I use the event of a non-dynamic control to call a sub that creates dynamic labels, textboxes and a button and the button's event. The problem is the button's event never fires. I have autopostback set to True for the dropdownlist and the option buttons. Here follows code snippets...
Public Class TroubleTicket
Inherits System.Web.UI.Page
Protected WithEvents optMenu As RadioButtonList
Protected WithEvents lstUsers As System.Web.UI.WebControls.DropDownList
' the radio button option "Add new user" calls DisplaylstUsers()
Private Sub DisplaylstUsers()
'code here fills lstUser from a db
lstUsers.AutoPostBack = True ' Negates need for a submit button
AddHandler lstUsers.SelectedIndexChanged, AddressOf lstUsers_OnChange
end sub
Private Sub lstUsers_OnChange(ByVal sender As Object, ByVal e As EventArgs) Handles lstUsers.SelectedIndexChanged
Select Case lstUsers.SelectedItem.Text
Case "-Make a selection-"
' do nothing
Case "Add a new user"
Display_TextBoxes() ' Input boxes for new user info to add to database
Case Else
DisplayTickets(CInt(lstUsers.SelectedItem.Value)) ' All tickets for particular user
End Select
End Sub ' lstUsers_OnChange()
' in lstUsers I select "Add a new user" which calls Display_TextBoxes()
Public Sub Display_TextBoxes()
Dim btnNewUser As New System.Web.UI.HtmlControls.HtmlButton()
With btnNewUser
.ID = "btnNUser"
.InnerText = "Add New User"
.Visible = True
End With
AddHandler btnNewUser.ServerClick, New EventHandler(AddressOf dxaBtnClk)
Me.FindControl("Form1").Controls.Add(btnNewUser)
end sub
' I click btnNewUser but never get to...
Public Sub dxaBtnClk(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("dxaBtnClk was clicked")
End Sub ' dxaBtnClk
End Class
Dynamic button event won't fire
Thanks for the reply and sorry for the dumb code.
That HTML button code was a desparate attempt to find a solution. The original and current code for the button is...
Dim btnNewUser As New Button()
With btnNewUser
.ID = "btnNUser"
.Text = "Add New User"
.Style.Item("position") = "absolute" ' necessary to keep controls from laying out wacky
.Style.Item("top") = "400px" 'iNewTop.ToString
.Style.Item("left") = "200px" 'arrTextBoxes(iColCount - 1).Style.Item("left")
.Visible = True
.CausesValidation = True
End With
AddHandler btnNewUser.Click, AddressOf dxaBtnClk
Me.FindControl("Form1").Controls.Add(btnNewUser)
Any ideas why the dxaBtnClk() doesn't fire?
Dynamic button event won't fire
My VS.NET has become corrupted and I'm having problems reinstalling. When I do reinstall I'll try out your suggestion.
Thanks,
David
Re: Dynamic button event won't fire
Quote:
Originally Posted by davidrobin
PopsMcF:
Did this work?
I am trying to do something similar.
To answer my own question, it does work.
Thanks BlahDos