473,802 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamicly created Radio Buttons

I have the following Code:

foreach (MyClass d in myClassCollecti on)
{
curRadioBtn = new RadioButton();
curRadioBtn.Tex t = d.ToString();
curRadioBtn.Gro upName = "Contact";
curRadioBtn.ID = d.Name;
curRadioBtn.Ena bleViewState = true;
curRadioBtn.Che ckedChanged += RadioButton_Che ckedChanged;
curPanel = new Panel();
curPanel.Height = curRadioBtn.Hei ght;
curPanel.Contro ls.Add(curRadio Btn);
panel1.Controls .Add(curPanel);
}

and I have two other RadioButtons on the form already, they are on Panel1.
The ones on the form cause RadioButton_Che ckedChanged to be fired on a post
back, but the dynamiclly created ones don't.

The questions I have are:
1) How do I cause the dynamic radio buttons to fire the event?
2) How do I tell which one is selected, out side of firing the event?
I know I can get the ID in the event from the sender, just curious
on how to do it without the event.
3) When I do the post back all the dynamicly created RadioButtons go away,
how do I force the page to remember them when it's redisplayed without
having to re-create them?

Thanks
Wayne Sepega
Jan 5 '06 #1
2 1699
Hi,

there would be answers to those questions, however, have you considered
using easier approach, such as creating them with a Repeater?

Sample (though with textBoxes)
http://forums.asp.net/1158998/ShowPost.aspx

But quick replies:

1. Dynamic controls need to be added on every request and on request
(postback) expecting the events to be raised, they need to be added to
Controls collection at Load event, because postback data loading happens
last time (fixed stage) right after Load.

2. There's not very practical ways. It would need inspecting Request.Form
collection, and locating the control with key there (matching control's
UniqueID), and then getting reference to the instance with Page.FindContro l

3. Either with repeater as I demonstrated (Repeater handles control
recreation dirty work), or then just you need to create them on postback,
because postback events won't be raised otherwise.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Wayne Sepega" <Me******@commu nity.nospam> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl...
I have the following Code:

foreach (MyClass d in myClassCollecti on)
{
curRadioBtn = new RadioButton();
curRadioBtn.Tex t = d.ToString();
curRadioBtn.Gro upName = "Contact";
curRadioBtn.ID = d.Name;
curRadioBtn.Ena bleViewState = true;
curRadioBtn.Che ckedChanged += RadioButton_Che ckedChanged;
curPanel = new Panel();
curPanel.Height = curRadioBtn.Hei ght;
curPanel.Contro ls.Add(curRadio Btn);
panel1.Controls .Add(curPanel);
}

and I have two other RadioButtons on the form already, they are on Panel1.
The ones on the form cause RadioButton_Che ckedChanged to be fired on a
post back, but the dynamiclly created ones don't.

The questions I have are:
1) How do I cause the dynamic radio buttons to fire the event?
2) How do I tell which one is selected, out side of firing the event?
I know I can get the ID in the event from the sender, just curious
on how to do it without the event.
3) When I do the post back all the dynamicly created RadioButtons go away,
how do I force the page to remember them when it's redisplayed without
having to re-create them?

Thanks
Wayne Sepega

Jan 5 '06 #2
Here are a few articles that will help to explain the sequence of things and
WHY controls need to be reloaded on each postback - and which event to use -
and other concepts relevant to your question.

http://aspnet.4guysfromrolla.com/articles/081402-1.aspx

http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

http://aspalliance.com/642

http://msdn.microsoft.com/library/de...nLifecycle.asp

http://www.15seconds.com/issue/020102.htm

http://www.eggheadcafe.com/articles/20050609.asp

http://msdn.microsoft.com/library/de...structures.asp

-HTH
"Wayne Sepega" <Me******@commu nity.nospam> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl...
I have the following Code:

foreach (MyClass d in myClassCollecti on)
{
curRadioBtn = new RadioButton();
curRadioBtn.Tex t = d.ToString();
curRadioBtn.Gro upName = "Contact";
curRadioBtn.ID = d.Name;
curRadioBtn.Ena bleViewState = true;
curRadioBtn.Che ckedChanged += RadioButton_Che ckedChanged;
curPanel = new Panel();
curPanel.Height = curRadioBtn.Hei ght;
curPanel.Contro ls.Add(curRadio Btn);
panel1.Controls .Add(curPanel);
}

and I have two other RadioButtons on the form already, they are on Panel1.
The ones on the form cause RadioButton_Che ckedChanged to be fired on a
post back, but the dynamiclly created ones don't.

The questions I have are:
1) How do I cause the dynamic radio buttons to fire the event?
2) How do I tell which one is selected, out side of firing the event?
I know I can get the ID in the event from the sender, just curious
on how to do it without the event.
3) When I do the post back all the dynamicly created RadioButtons go away,
how do I force the page to remember them when it's redisplayed without
having to re-create them?

Thanks
Wayne Sepega

Jan 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11205
by: Raghuram Banda | last post by:
Hi All, The following is the function I used to create RADIO buttons using DOM. It works fine with Netscape but not with IE. function addGroup3Radio() { var cellId = document.getElementById("cell1"); for(var i=0; i < arrData.length; i++) { var objRadItem = document.createElement("input"); objRadItem.type = "radio"; objRadItem.name = "radGroup";
4
3283
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
6
3295
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked The problem i am facing is that i do not know how many yes/no radio groups will be generated
1
6892
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
2
5897
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on the form by changing the visible state of the radio buttons and labels utilising back and next buttons. E.g. Next button makes current radio buttons and labels invisible and
4
2522
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see all twelve. User2 would see buttons 1-3,10-12 and NOT any others, and so on. Since there are several buttons on the page (each one would run a report for them), is there a way to - in an onclick event for each of the buttons - to...
2
1138
by: Chris Monro | last post by:
Hi! I've created a UI control that adds(Creates) or subtracts(Destroys) standard buttons on a panel. I want to have each of these created buttons become accessible as UI elements, just as the custom control itself is, so that if the control has been defined by property to have 2 buttons, then the buttons themselves have standard properties accessible to the user of the control, so things like color, etc... as well as events can be tied...
7
4876
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio buttons and check box. I am adding two radio buttons once for a row.Now my problem is the radio buttons in all the rows that added dynamically are behaving as same group i.e when i am selecting a radio button in second row,radio button in first row...
5
6707
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con = ConfigurationManager.ConnectionStrings.ConnectionString; protected void Page_Load(object sender, EventArgs e) { try
0
9699
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.