|
-
Jun 24th, 2002, 11:12 AM
#1
Thread Starter
Junior Member
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
-
Jun 24th, 2002, 11:25 AM
#2
Dim btnNewUser As New System.Web.UI.HtmlControls.HtmlButton()
^^^
you are creating a client side html button, not a server side web forms button. Client side cant run server side functions.
-
Jun 24th, 2002, 11:54 AM
#3
Thread Starter
Junior Member
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?
-
Jun 25th, 2002, 01:41 PM
#4
Lively Member
try this
addhandler yourbuttonname.click, new system.eventhandler(addressOf the_function_that_you_want_to_call_when_pressing_the_button)
-
Jun 25th, 2002, 03:43 PM
#5
Thread Starter
Junior Member
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
-
Oct 14th, 2004, 05:37 AM
#6
Fanatic Member
PopsMcF:
Did this work?
I am trying to do something similar.
-
Jun 23rd, 2005, 04:23 AM
#7
Fanatic Member
Re: Dynamic button event won't fire
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|