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. 5 2704
Hi,
"Steve Moreno" <St*********@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.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. 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.
exact
:-)
Cor
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.
"Bart Mermuys" wrote: Hi,
"Steve Moreno" <St*********@discussions.microsoft.com> wrote in message news:A9**********************************@microsof t.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.
"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.
Had same problem, hence the reason for finding this thread.
Solved by adding this last line to similar code:
quest_id = New DropDownList
AddHandler quest_id.SelectedIndexChanged, AddressOf updateScore
quest_id.AutoPostBack = True
The event now fires!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrés Giraldo |
last post by:
Hi!
I'm adding an asp button to a datagrid on the ItemDataBound event, when
the user clicks on this button, I basically remove the button and create
other 2 buttons... my problem is.. the 2 last...
|
by: Nathan Sokalski |
last post by:
I am trying to dynamically add controls to my page, but am having trouble
with controls such as buttons. I have been able to add simple controls such
as Label controls, because they can be placed...
|
by: Oddball |
last post by:
I am trying to create and add a number of ImageButtons to a page when a certain
event is called.
Not only am I suffering from my page running the "Page_Load" event three times, but I
can't seem...
|
by: Mark Rae |
last post by:
Hi,
Is it possible to add events, specifically a Click event, to a dynamically
created TableCell?
I have an <asp:Table...> control to which I'm dynamically adding TableRow
controls made up of...
|
by: Mike Lowery |
last post by:
I have an ASP.Net page that simply generates a dynamic page using
Response.Write() statements to generate the HTML. This works great except that
one of the things I want to generate is a...
|
by: Michael Lang |
last post by:
I'm adding checkbox controls to a panel in a post back, I then have a second
post back in which I attempt to process the checkbox controls however they
seem to have disappeared off the panel. The...
|
by: Amoril |
last post by:
I've read quite a few different message on various boards and for some
reason I'm still having trouble wrapping my head around this viewstate
maintenance and trying to get these dynamically created...
|
by: ChrisCicc |
last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
|
by: Klaus Jensen |
last post by:
Subject: Handling events of controls created at runtime
I need to render some buttons at runtime based on a database, tie events to
them, and handle the events when they fire.
In Page_Load I...
|
by: Lewis Holmes |
last post by:
Hi
I have the following situation in one of my asp.net pages.
The user can add multiple table rows to a form by selecting a button. These
rows can contain asp.net controls. When this button is...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |