Hi,
I can't seem to find much information on this. Please could someone explain
to me how to wire up events (selectedIndexChanged) to a bunch of dynamically
created controls (Dropdownlists), preferably in C#. I'm sure this should be
relatively straighforward, but can't for the life of me figure out a good
way of doing it.
Many thanks!
S 5 1950
Private Sub Tester()
Dim list As New DropDownList
list.Items.Add("one")
list.Items.Add("two")
list.Items.Add("three")
list.Items.Add("four")
AddHandler list.SelectedIndexChanged, AddressOf listClick
End Sub
Protected Sub listClick(ByVal sender As Object, ByVal e As EventArgs)
'add your code here
End Sub
"Sosh" <so*******@something.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Hi,
I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists), preferably in C#. I'm sure this should be relatively straighforward, but can't for the life of me figure out a good way of doing it.
Many thanks!
S
Yeah thats what I'm doing at the moment (well at least the c# equivalent).
However the event handler is not being called. Heres a sumary, phDropDowns
is a placeholder, DDL SelectedIndexChanged never gets called. I have a
feeling this is something to do with the Page.IsPostBack, but how else would
you do it?
Thanks
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DropDownList tempDDL = new DropDownList();
tempDDL.SelectedIndexChanged += new
System.EventHandler(DDL_SelectedIndexChanged);
tempDDL.AutoPostBack = true;
phDropDowns.Controls.Add(tempDDL);
}
}
"Dimitrios Toulakis" <ma*********@web.de> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl... Private Sub Tester()
Dim list As New DropDownList
list.Items.Add("one")
list.Items.Add("two")
list.Items.Add("three")
list.Items.Add("four")
AddHandler list.SelectedIndexChanged, AddressOf listClick End Sub Protected Sub listClick(ByVal sender As Object, ByVal e As EventArgs)
'add your code here
End Sub "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Hi,
I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists), preferably in C#. I'm sure this should be relatively straighforward, but can't for the life of me figure out a good way of doing it.
Many thanks!
S
Sosh,
set the autopostback property of the dropdown to true
Dimi
"Sosh" <so*******@something.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Yeah thats what I'm doing at the moment (well at least the c# equivalent). However the event handler is not being called. Heres a sumary, phDropDowns is a placeholder, DDL SelectedIndexChanged never gets called. I have a feeling this is something to do with the Page.IsPostBack, but how else would you do it?
Thanks
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DropDownList tempDDL = new DropDownList();
tempDDL.SelectedIndexChanged += new System.EventHandler(DDL_SelectedIndexChanged);
tempDDL.AutoPostBack = true;
phDropDowns.Controls.Add(tempDDL);
} }
"Dimitrios Toulakis" <ma*********@web.de> wrote in message news:u5**************@TK2MSFTNGP14.phx.gbl... Private Sub Tester()
Dim list As New DropDownList
list.Items.Add("one")
list.Items.Add("two")
list.Items.Add("three")
list.Items.Add("four")
AddHandler list.SelectedIndexChanged, AddressOf listClick End Sub Protected Sub listClick(ByVal sender As Object, ByVal e As EventArgs)
'add your code here
End Sub "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Hi,
I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists), preferably in C#. I'm sure this should be relatively straighforward, but can't for the life of me figure out a good way of doing it.
Many thanks!
S
Hi Dimi,
I'm already setting it to true (see below) - the page is being posted back,
but the event handler is not called
Thanks
"Dimitrios Toulakis" <ma*********@web.de> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl... Sosh,
set the autopostback property of the dropdown to true
Dimi "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... Yeah thats what I'm doing at the moment (well at least the c# equivalent). However the event handler is not being called. Heres a sumary, phDropDowns is a placeholder, DDL SelectedIndexChanged never gets called. I have a feeling this is something to do with the Page.IsPostBack, but how else would you do it?
Thanks
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DropDownList tempDDL = new DropDownList();
tempDDL.SelectedIndexChanged += new System.EventHandler(DDL_SelectedIndexChanged);
tempDDL.AutoPostBack = true;
phDropDowns.Controls.Add(tempDDL);
} }
"Dimitrios Toulakis" <ma*********@web.de> wrote in message news:u5**************@TK2MSFTNGP14.phx.gbl... Private Sub Tester()
Dim list As New DropDownList
list.Items.Add("one")
list.Items.Add("two")
list.Items.Add("three")
list.Items.Add("four")
AddHandler list.SelectedIndexChanged, AddressOf listClick End Sub Protected Sub listClick(ByVal sender As Object, ByVal e As EventArgs)
'add your code here
End Sub "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Hi,
I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists), preferably in C#. I'm sure this should be relatively straighforward, but can't for the life of me figure out a good way of doing it.
Many thanks!
S
Hi Sosh,
Your problem is due to the fact that you need to rebuild all the controls
you have dynamically created on each post back. Every time the page is posted
back all the dynamically created controls are lost. So you need to recreate
them.
This should be done on or before page_load. So create a function to create
your dynamic controls and call this function on every postback. Then the
control is recreated and its event can be fired.
Kind Regards
Warren
"Sosh" wrote: Hi Dimi,
I'm already setting it to true (see below) - the page is being posted back, but the event handler is not called
Thanks
"Dimitrios Toulakis" <ma*********@web.de> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Sosh,
set the autopostback property of the dropdown to true
Dimi "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... Yeah thats what I'm doing at the moment (well at least the c# equivalent). However the event handler is not being called. Heres a sumary, phDropDowns is a placeholder, DDL SelectedIndexChanged never gets called. I have a feeling this is something to do with the Page.IsPostBack, but how else would you do it?
Thanks
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DropDownList tempDDL = new DropDownList();
tempDDL.SelectedIndexChanged += new System.EventHandler(DDL_SelectedIndexChanged);
tempDDL.AutoPostBack = true;
phDropDowns.Controls.Add(tempDDL);
} }
"Dimitrios Toulakis" <ma*********@web.de> wrote in message news:u5**************@TK2MSFTNGP14.phx.gbl... Private Sub Tester()
Dim list As New DropDownList
list.Items.Add("one")
list.Items.Add("two")
list.Items.Add("three")
list.Items.Add("four")
AddHandler list.SelectedIndexChanged, AddressOf listClick End Sub Protected Sub listClick(ByVal sender As Object, ByVal e As EventArgs)
'add your code here
End Sub "Sosh" <so*******@something.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... > Hi, > > I can't seem to find much information on this. Please could someone > explain to me how to wire up events (selectedIndexChanged) to a bunch > of dynamically created controls (Dropdownlists), preferably in C#. I'm > sure this should be relatively straighforward, but can't for the life > of me figure out a good way of doing it. > > Many thanks! > > S >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oisin Grehan |
last post by:
Hi,
I have a UserControl derived class:
<ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" />
My question is, what code do I need in place in the codebehind for this to...
|
by: luca |
last post by:
Hi all.
My problem is that I can't handle events raised from child components within
a composite server control when the control is created dynamically.
Everything works fine if the same control...
|
by: Homam |
last post by:
To wire a Click event handler to a dynamically-added control (e.g.
LinkButton), you need to do so during the Load event of the parent (e.g. a
PlaceHolder).
The problem is, the Click event...
|
by: Steve Booth |
last post by:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all...
|
by: Jordan |
last post by:
I need to dynamically add an ImageButton control to a user control and and
do some server-side processing when the user clicks it. While I the
ImageButton is added to the user control at runtime,...
|
by: bill |
last post by:
I'm using VS2005.
I am dynamically adding a Textbox control to a Placeholder control in the
page_load event of the form, but the event handler isn't firing. What am I
doing wrong?
Thanks...
|
by: Andrew Robinson |
last post by:
I have a page that can load a number of different user controls. Each of
these user controls inherits from a common base class and the controls are
loaded based on application state, status, etc...
|
by: Redhairs |
last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?
|
by: CMELLO |
last post by:
I have am dynamically loading a web user control based on the click of
a tab strip
I load the default control for the first tab in the page load event
after checking page is not postback. After...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |