|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
2nd Post: Problem adding events to controls created at run-timeI've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is working fine but now I need to add events to the newly created DropDownList controls. I need to add the SelectedIndexChanged event and I'm having a hard time getting the code to add events to the controls since the names (IDs) are varied to include the record row number like "name & (int)". I've seen examples on other web-sites which have either syntax errors and/or so do not compile on my pc. So my question is this... If I have a group of dropdownlistboxes named dlstDropDown and I have changed the ID of the controls before I add the control to my page to include an index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... How do I add a SelectedIndexChanged event to each of them? And/Or how would I go about creating a generic private sub to capture this event? What I've tried so far with no success is: 'before I add the control to the page AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ Me.dlstWindow_SelectedIndexChanged It looks like the event either doesn't fire or isn't in the correct AddressOf. This is the sub I've been playing with: Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal _ e As System.EventArgs) Dim strCurrentID As String Dim currentDropDownList As DropDownList = CType(sender, DropDownList) strCurrentID = currentDropDownList.ID End Sub I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly appreciated. I've already burned an entire week on this and am working on burning another one. :( thanks in advance, Steve. I had already set the autopostback property to true but it didn't seem like
it got to the sub that I wanted it to process (listed below in original post). So looking at the way I'm setting a handler to that control, am I doing something wrong? Here's a more complete listing of the way I'm setting the hander to the controls. Could it be because I'm giving each dropdownlist control a unique ID? Do I have to use something like dlstWindow(integer).SelectedIndexChanged, AddressOf dlstWindowSelectedIndexChanged? Dim dlstWindow As DropDownList = New DropDownList AddHandler dlstWindow.SelectedIndexChanged, AddressOf dlstWindowSelectedIndexChanged For j = 0 To UBound(myWindows) dlstWindow.Items.Add(New ListItem(myWindows(j).ToString)) Next dlstWindow.SelectedValue = ds.Tables(0).Rows(i).ItemArray(0) dlstWindow.ID = "dlstWindow" & i DataPanel.Controls.Add(dlstWindow) Again, any help would be greatly appreciated. Thanks, Steve. Show quoteHide quote "Ken Tucker [MVP]" wrote: > Steve, > > The Selected Index Changed event firea when the web page posts back. > Make sure the dropdownlist's autopostback property is set to true. > > Ken > ----------------------- > > "Steve Moreno" wrote: > > > Hi all, > > > > I've got a web form that I've written code to create an array of > > DropDownList controls on the page depending on how many records are pulled > > back. The code to create the controls is working fine but now I need to add > > events to the newly created DropDownList controls. I need to add the > > SelectedIndexChanged event and I'm having a hard time getting the code to add > > events to the controls since the names (IDs) are varied to include the record > > row number like "name & (int)". > > > > I've seen examples on other web-sites which have either syntax errors and/or > > so do not compile on my pc. So my question is this... > > > > If I have a group of dropdownlistboxes named dlstDropDown and I have changed > > the ID of the controls before I add the control to my page to include an > > index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... > > How do I add a SelectedIndexChanged event to each of them? And/Or how would > > I go about creating a generic private sub to capture this event? > > > > What I've tried so far with no success is: > > > > 'before I add the control to the page > > AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ > > Me.dlstWindow_SelectedIndexChanged > > > > It looks like the event either doesn't fire or isn't in the correct > > AddressOf. This is the sub I've been playing with: > > > > Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal _ > > e As System.EventArgs) > > > > Dim strCurrentID As String > > Dim currentDropDownList As DropDownList = CType(sender, DropDownList) > > > > strCurrentID = currentDropDownList.ID > > > > End Sub > > > > I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly > > appreciated. I've already burned an entire week on this and am working on > > burning another one. :( > > > > thanks in advance, > > Steve. > > Steve,
The Selected Index Changed event firea when the web page posts back. Make sure the dropdownlist's autopostback property is set to true. Ken ----------------------- Show quoteHide quote "Steve Moreno" wrote: > Hi all, > > I've got a web form that I've written code to create an array of > DropDownList controls on the page depending on how many records are pulled > back. The code to create the controls is working fine but now I need to add > events to the newly created DropDownList controls. I need to add the > SelectedIndexChanged event and I'm having a hard time getting the code to add > events to the controls since the names (IDs) are varied to include the record > row number like "name & (int)". > > I've seen examples on other web-sites which have either syntax errors and/or > so do not compile on my pc. So my question is this... > > If I have a group of dropdownlistboxes named dlstDropDown and I have changed > the ID of the controls before I add the control to my page to include an > index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... > How do I add a SelectedIndexChanged event to each of them? And/Or how would > I go about creating a generic private sub to capture this event? > > What I've tried so far with no success is: > > 'before I add the control to the page > AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ > Me.dlstWindow_SelectedIndexChanged > > It looks like the event either doesn't fire or isn't in the correct > AddressOf. This is the sub I've been playing with: > > Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal _ > e As System.EventArgs) > > Dim strCurrentID As String > Dim currentDropDownList As DropDownList = CType(sender, DropDownList) > > strCurrentID = currentDropDownList.ID > > End Sub > > I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly > appreciated. I've already burned an entire week on this and am working on > burning another one. :( > > thanks in advance, > Steve. > Hi,
Show quoteHide quote "Steve Moreno" <SteveMor***@discussions.microsoft.com> wrote in message I rarely make webapplications, but from what i remember you need to news:A98C5DF6-484A-4B4A-9671-04B5DE6D7D86@microsoft.com... > Hi all, > > I've got a web form that I've written code to create an array of > DropDownList controls on the page depending on how many records are pulled > back. The code to create the controls is working fine but now I need to > add > events to the newly created DropDownList controls. I need to add the > SelectedIndexChanged event and I'm having a hard time getting the code to > add > events to the controls since the names (IDs) are varied to include the > record > row number like "name & (int)". > > I've seen examples on other web-sites which have either syntax errors > and/or > so do not compile on my pc. So my question is this... > > If I have a group of dropdownlistboxes named dlstDropDown and I have > changed > the ID of the controls before I add the control to my page to include an > index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... > How do I add a SelectedIndexChanged event to each of them? And/Or how > would > I go about creating a generic private sub to capture this event? > > What I've tried so far with no success is: > > 'before I add the control to the page > AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ > Me.dlstWindow_SelectedIndexChanged > > It looks like the event either doesn't fire or isn't in the correct re-create the dynamic Controls in Page_Load with the same ID. WebPage's are static, so when the page is loaded again (because of postback) the dynamic controls are gone so their events can't fire. But if you re-create them inside Page_Load with the same id, then their events will fire. HTH, Greetings Show quoteHide quote > AddressOf. This is the sub I've been playing with: > > Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal > _ > e As System.EventArgs) > > Dim strCurrentID As String > Dim currentDropDownList As DropDownList = CType(sender, > DropDownList) > > strCurrentID = currentDropDownList.ID > > End Sub > > I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly > appreciated. I've already burned an entire week on this and am working on > burning another one. :( > > thanks in advance, > Steve. > > I rarely make webapplications, but from what i remember you need to Cor> re-create the dynamic Controls in Page_Load with the same ID. WebPage's > are static, so when the page is loaded again (because of postback) the > dynamic controls are gone so their events can't fire. But if you > re-create them inside Page_Load with the same id, then their events will > fire. > exact :-) Thanks for trying to help. I am already generating these controls on the
Page_Load event. I'm thinking the SelectedIndexChanged events are firing but maybe my syntax for the handler sub is incorrect? Please check below and see if you can find an issue why this doesn't work. Thanks In Advance Again. Steve. Show quoteHide quote "Bart Mermuys" wrote: > Hi, > > "Steve Moreno" <SteveMor***@discussions.microsoft.com> wrote in message > news:A98C5DF6-484A-4B4A-9671-04B5DE6D7D86@microsoft.com... > > Hi all, > > > > I've got a web form that I've written code to create an array of > > DropDownList controls on the page depending on how many records are pulled > > back. The code to create the controls is working fine but now I need to > > add > > events to the newly created DropDownList controls. I need to add the > > SelectedIndexChanged event and I'm having a hard time getting the code to > > add > > events to the controls since the names (IDs) are varied to include the > > record > > row number like "name & (int)". > > > > I've seen examples on other web-sites which have either syntax errors > > and/or > > so do not compile on my pc. So my question is this... > > > > If I have a group of dropdownlistboxes named dlstDropDown and I have > > changed > > the ID of the controls before I add the control to my page to include an > > index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... > > How do I add a SelectedIndexChanged event to each of them? And/Or how > > would > > I go about creating a generic private sub to capture this event? > > > > What I've tried so far with no success is: > > > > 'before I add the control to the page > > AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ > > Me.dlstWindow_SelectedIndexChanged > > > > It looks like the event either doesn't fire or isn't in the correct > > I rarely make webapplications, but from what i remember you need to > re-create the dynamic Controls in Page_Load with the same ID. WebPage's are > static, so when the page is loaded again (because of postback) the dynamic > controls are gone so their events can't fire. But if you re-create them > inside Page_Load with the same id, then their events will fire. > > HTH, > Greetings > > > > AddressOf. This is the sub I've been playing with: > > > > Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal > > _ > > e As System.EventArgs) > > > > Dim strCurrentID As String > > Dim currentDropDownList As DropDownList = CType(sender, > > DropDownList) > > > > strCurrentID = currentDropDownList.ID > > > > End Sub > > > > I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly > > appreciated. I've already burned an entire week on this and am working on > > burning another one. :( > > > > thanks in advance, > > Steve. > > > > > Got it!!!!!!!!!!!!!!
With the replies I've received from Ken, Bart, and Cor I've realized that I had the code that creates the controls within a "If Not IsPostBack Then" block and so the controls were not being re-created and thus events were indeed not firing. Something so obvious and yet not obvious until you hear from others... Now that I've modified the code to reside outside of the "If Not IsPostBack Then" block, it works GREAT! Thanks to all who have replied. Steve. Show quoteHide quote "Steve Moreno" wrote: > Hi all, > > I've got a web form that I've written code to create an array of > DropDownList controls on the page depending on how many records are pulled > back. The code to create the controls is working fine but now I need to add > events to the newly created DropDownList controls. I need to add the > SelectedIndexChanged event and I'm having a hard time getting the code to add > events to the controls since the names (IDs) are varied to include the record > row number like "name & (int)". > > I've seen examples on other web-sites which have either syntax errors and/or > so do not compile on my pc. So my question is this... > > If I have a group of dropdownlistboxes named dlstDropDown and I have changed > the ID of the controls before I add the control to my page to include an > index so they would be dlstDropDown0, dlstDropDown1, dlstDropDown2, etc... > How do I add a SelectedIndexChanged event to each of them? And/Or how would > I go about creating a generic private sub to capture this event? > > What I've tried so far with no success is: > > 'before I add the control to the page > AddHandler dlstWindow.SelectedIndexChanged, AddressOf _ > Me.dlstWindow_SelectedIndexChanged > > It looks like the event either doesn't fire or isn't in the correct > AddressOf. This is the sub I've been playing with: > > Private Sub dlstWindow_SelectedIndexChanged(ByVal sender As Object, ByVal _ > e As System.EventArgs) > > Dim strCurrentID As String > Dim currentDropDownList As DropDownList = CType(sender, DropDownList) > > strCurrentID = currentDropDownList.ID > > End Sub > > I'm using 2003 (haven't migrated to 2005 yet). Any help would be greatly > appreciated. I've already burned an entire week on this and am working on > burning another one. :( > > thanks in advance, > Steve. >
For each
Lock statement in C#, Is there an equivalent in VB.NET? KeyUp + KeyDown Event Handler Calculate elapsed time Multiple threads using a shared printer resource Help needed on creating Shared Directory progress bar convert text to access mdb Structured files in VS 2005 halt application flow until condition is met |
|||||||||||||||||||||||