473,763 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RadioButtonList created in the page load event

If I create a RadioButtonList with, say, two items, then after the page
loads and I select one of the items and then click on a button whose click
event contains some code to display the RadioButtonlLis t's selected value,
there is nothing.

On a postback, with the dynamically created button list visible on the page
and the first item selected, if I try some code like "If
Me.RadioButtonL ist1.Items(0).S elected = True Then.......", then I get an
index out of range error. It is like the RadiobuttonList does not really
exits.

For RadioButtonList s that are simply dropped on a page with their values set
in the properties window in Visual Studio, there is no problem.

So, how does one determine whether a dynamically created RadioButtonList
item is selected and if so what its selected value is?

Nov 18 '05 #1
3 9007
Hi,

if you create the RadioButtonList at Page_load, it's state/data is available
after postback events which happen after Page_Load have occurred.

i.e page lifecycle on every request is:

1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDataha ndler.LoadPostd ata)
6. Load
7. Load postback data for dynamical controls added on Page_Load (postback)
8. Raise Changed Events (postback,
IPostBackDataha ndler.RaisePost DataChanged)
9. Raise postback event (postback, IPostBackEventH andler.RaisePos tBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

As you can see, so if on initial request you create the RadioButtonList in
Page_load, it hasn't yet loaded its state at Page_Load phase on postback. As
a solution, you could move the creation of control into Page_Init, when
state is available at Page_Load, or move checking the selection to PreRender
phase.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"William LaMartin" <la******@tampa bay.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
If I create a RadioButtonList with, say, two items, then after the page
loads and I select one of the items and then click on a button whose click
event contains some code to display the RadioButtonlLis t's selected value,
there is nothing.

On a postback, with the dynamically created button list visible on the page and the first item selected, if I try some code like "If
Me.RadioButtonL ist1.Items(0).S elected = True Then.......", then I get an
index out of range error. It is like the RadiobuttonList does not really
exits.

For RadioButtonList s that are simply dropped on a page with their values set in the properties window in Visual Studio, there is no problem.

So, how does one determine whether a dynamically created RadioButtonList
item is selected and if so what its selected value is?

Nov 18 '05 #2
Thanks for the suggestions. I put the code that creates the RadioButtonList
in Page_Init with no change. I then put the check for selected value in
Page_PreRender, also with no change. The code used is below.

I will study your sequence of events and see if that can somehow lead to a
solution to the problem. I have run into similar situations when I wanted
to set a Session variable and then use it on a button click, but the session
variable was a click behind when I needed it.

Code that creates the RadioButtonList :

Dim filepath As String
Dim filename As String
Dim RadioButtonList 1 As New RadioButtonList
RadioButtonList 1.ID = "AcrobatRBL "
RadioButtonList 1.Visible = True
RadioButtonList 1.EnableViewSta te = True
RadioButtonList 1.AutoPostBack = True
Me.Panel1.Visib le = True
Me.Panel1.Contr ols.Clear()
filepath = Server.MapPath( ".") & "\acrobat_files \"
Dim CurrentDirector y As New System.IO.Direc toryInfo(filepa th)
Dim FileArray() As System.IO.FileI nfo
FileArray = CurrentDirector y.GetFiles()
Dim i As Integer
For i = FileArray.GetLo werBound(0) To FileArray.GetUp perBound(0)
Dim mylistItem As New ListItem
mylistItem.Text = FileArray(i).Na me
mylistItem.Valu e = FileArray(i).Na me
RadioButtonList 1.Items.Add(myl istItem)
Next i
Me.Panel1.Contr ols.Add(RadioBu ttonList1)

Code to check the selected value:

Me.Label2.Text = Me.RadioButtonL ist2.SelectedVa lue
"Teemu Keiski" <jo****@aspalli ance.com> wrote in message
news:e1******** *****@tk2msftng p13.phx.gbl...
Hi,

if you create the RadioButtonList at Page_load, it's state/data is available after postback events which happen after Page_Load have occurred.

i.e page lifecycle on every request is:

1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDataha ndler.LoadPostd ata)
6. Load
7. Load postback data for dynamical controls added on Page_Load (postback)
8. Raise Changed Events (postback,
IPostBackDataha ndler.RaisePost DataChanged)
9. Raise postback event (postback, IPostBackEventH andler.RaisePos tBackEvent) 10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

As you can see, so if on initial request you create the RadioButtonList in
Page_load, it hasn't yet loaded its state at Page_Load phase on postback. As a solution, you could move the creation of control into Page_Init, when
state is available at Page_Load, or move checking the selection in Page_PreRend phase.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"William LaMartin" <la******@tampa bay.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
If I create a RadioButtonList with, say, two items, then after the page
loads and I select one of the items and then click on a button whose click event contains some code to display the RadioButtonlLis t's selected value, there is nothing.

On a postback, with the dynamically created button list visible on the

page
and the first item selected, if I try some code like "If
Me.RadioButtonL ist1.Items(0).S elected = True Then.......", then I get an
index out of range error. It is like the RadiobuttonList does not really exits.

For RadioButtonList s that are simply dropped on a page with their values

set
in the properties window in Visual Studio, there is no problem.

So, how does one determine whether a dynamically created RadioButtonList
item is selected and if so what its selected value is?


Nov 18 '05 #3
Problem solved. It really had nothing to do with the RadioButtonList being
created on the fly. The problem was caused by there being to declarations
of the RadioButtonList--one at the page level and one at the page_load event
level. When I realized this and removed the one at the page_load event
level, there ceased to be a problem.
"William LaMartin" <la******@tampa bay.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
If I create a RadioButtonList with, say, two items, then after the page
loads and I select one of the items and then click on a button whose click
event contains some code to display the RadioButtonlLis t's selected value,
there is nothing.

On a postback, with the dynamically created button list visible on the page and the first item selected, if I try some code like "If
Me.RadioButtonL ist1.Items(0).S elected = True Then.......", then I get an
index out of range error. It is like the RadiobuttonList does not really
exits.

For RadioButtonList s that are simply dropped on a page with their values set in the properties window in Visual Studio, there is no problem.

So, how does one determine whether a dynamically created RadioButtonList
item is selected and if so what its selected value is?


Nov 18 '05 #4

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

Similar topics

5
5511
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 -- -- BoundColumn 1 -- -- BoundColumn 2 -- -- TemplateColumn 4 -- -- RadioButtonList --
6
7771
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and update the database. Here is the control containment hierarchy: ASP Page Static User Control // just provides a pretty border around
3
1419
by: Mark Broadbent | last post by:
try as I might (and using different properties) this control always seems to be returning the first element of the control as the "selected" item even though I am selecting the second element. All I need it the index number to reference a particular row num of a dataset. I only just noticed this today but it if I cant determine the selected radiobuttonlist item then it reders this control useless. Hope someone can help? --
5
3370
by: Mike Salter | last post by:
I created a page that reads a DB for questions and possible answers (usuallyYes/No). I create a panel for each group of questions, and add a panel for each question to the Group panel. To the Question panel I add a label with the question text, and a radiobuttonlist with the answers. I have an eventhandler I add to each radiobuttonlist, which is the same for all. The Group panels are then added to Placeholder1.Controls. I then add...
0
1058
by: Quinn | last post by:
Hi, I have the same problem as this topic posted http://groups-beta.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/a7eb51bd33f2becf/c0e83f77395fbf64?lnk=st&q=radiobuttonlist+event+in+datagrid&rnum=2&hl=en#c0e83f77395fbf64 however, when I copied the code, everything works fine, except the SelectedIndexchanged event for the radiobuttonlist in the template column of hte datagrid does not fire. I wonder if...
4
4003
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The radiobuttonlist contains two items (yes,no). Both the checkboxes and the radiobuttonlist are NOT autopostbacked ( .autopostback = false). When i press the submit button a sub (submit_pressed) is run. My problem is that i can not get the selected items...
5
2691
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hallo, I have a radiobuttonlist control that is added on a custom Web User Control. This control has a property that exposes the SelectedIndex property of the embedded radiobuttonlist. When running this in IE, behaviour is as I would expect it. If I select an item and do a postback, the page remembers my selection when reloading, and the SelectedIndex property of my control returns the correct value.
6
2643
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered in the page and I've got code to get the selected value from it in the Radiobuttonlist_SelectedIndexChanged event. The code in there is: Protected Sub rblFMSValue_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
13
10722
by: tommymo | last post by:
Hi everyone I'm new to this site and the world of ASP.Net C# programming. I have been learning controls and integrating them with a SQL database. So far I have been able to move along and understand static controls. However I would like to move on to attempt to create some dynamic controls. So I set out to work with a radiobuttonlist questionnaire. I have a database and in that DB I have 2 tables one which holds the questions and the other...
0
9563
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
9386
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
10145
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...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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
8822
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...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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

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.