473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

nested web control postback selections not updated before page_load

Group,

I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which
contains nested server user controls in order to create a tree-like
hierarchy.

The tree is a sort of question and answer dialog. The user answers a
question, and the next subquestion appears (using dynamic html
display:none|block) depending on his answer.

When all the questions are answered, the webform is posted.

Based on my reading, I understand that I have to recreate the nested
control structure in the OnInit event before the postback data is
applied to my dynamic server controls.

So, I grab my "active" question from the Session state and proceed to
rebuild my tree of controls using a method, appropriately named,
createDynamicControls.

I have verified at the end of the OnInit that the hierarchy is rebuilt
and I'm trusting the IDs to be created the same way, seeing how the
same method is used to always recreate the heirarchy.

Now, I *believe* after the init event, ASP.NET is supposed "fill-in"
the selected values in the form and then fire the page_load events for
the controls. Is this true? Because...

When I inspect my nested control tree in page_load, the state of my
radio buttons is not changed.

Architecturally, I have two custom System.Web.UI.UserControls:
QuestionManager
QuestionItem

QuestionManager has a placeholder on which QuestionItems are arranged.
QuestionItem contains two server controls:
A label for the question text
A placeholder for the answers

Answers are Radiobutton lists of possible answers. For each answer
(radio button list item), there may be a further subquestions.

If there are answer-dependent sub-questions, QuestionItems are created
for them and they are added to the parent answer placeholder
(display:none) and the display is manipulated on the client in
javascript based on the selected answer.

The tree displays nicely on the client, they can select radio buttons,
the appropriate subquestions become visible and life seems good.

--Until the postback.

A. is this a stupid architecture?
B. can it ever work?
C. why doesn't it work? i.e. why are the altered radiobuttons not
ready for me in page_load?

Thanks in advance,
Sorry if this is a newbie question on the wrong group; if it is kindly
redirect me to the appropriate group.

Brad

Feb 5 '07 #1
2 2394
I'll answer my own post.

The radio buttons didn't change because the IDs were not preserved. I
was depending on the generated IDs, but there are two places where the
question tree is generated:

1. In the init event on postbacks
2. In the load event on postbacks when I detect a user-initiated
change in a dropdownlist which requires a different line of
questioning.

In the inits, the assigned IDs started with ctl0_ ctl1_ etc..
However, in the loads, the assigned ids started with 1 not 0. ctl1_
ctl2_ etc even though I had done a Controls.clear to start with in
both cases.

So none of my postback data lined up with my reconstructed view
state. All I had to do was simply set the IDs in code and life was
good again. Lesson learned: never count on generated IDs when using
dynamic controls.

But it begs this question:

Can I get at postback data that doesn't re-bind to a control ID? Is
it in a collection somewhere or is it buried in the .response?

Brad

On Feb 5, 10:41 am, "brad" <brad.eckr...@gmail.comwrote:
Group,

I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which
contains nested server user controls in order to create a tree-like
hierarchy.

The tree is a sort of question and answer dialog. The user answers a
question, and the next subquestion appears (using dynamic html
display:none|block) depending on his answer.

When all the questions are answered, the webform is posted.

Based on my reading, I understand that I have to recreate the nested
control structure in the OnInit event before the postback data is
applied to my dynamic server controls.

So, I grab my "active" question from the Session state and proceed to
rebuild my tree of controls using a method, appropriately named,
createDynamicControls.

I have verified at the end of the OnInit that the hierarchy is rebuilt
and I'm trusting the IDs to be created the same way, seeing how the
same method is used to always recreate the heirarchy.

Now, I *believe* after the init event, ASP.NET is supposed "fill-in"
the selected values in the form and then fire the page_load events for
the controls. Is this true? Because...

When I inspect my nested control tree in page_load, the state of my
radio buttons is not changed.

Architecturally, I have two custom System.Web.UI.UserControls:
QuestionManager
QuestionItem

QuestionManager has a placeholder on which QuestionItems are arranged.
QuestionItem contains two server controls:
A label for the question text
A placeholder for the answers

Answers are Radiobutton lists of possible answers. For each answer
(radio button list item), there may be a further subquestions.

If there are answer-dependent sub-questions, QuestionItems are created
for them and they are added to the parent answer placeholder
(display:none) and the display is manipulated on the client in
javascript based on the selected answer.

The tree displays nicely on the client, they can select radio buttons,
the appropriate subquestions become visible and life seems good.

--Until the postback.

A. is this a stupid architecture?
B. can it ever work?
C. why doesn't it work? i.e. why are the altered radiobuttons not
ready for me in page_load?

Thanks in advance,
Sorry if this is a newbie question on the wrong group; if it is kindly
redirect me to the appropriate group.

Brad

Feb 5 '07 #2
And the final lesson learned: ListItems in a RadioButtonList *MUST*
contain unique values otherwise the "selected" state will not get
restored properly. It's probably in some documentation that I
skimmed, but that was the final puzzle piece.

Brad

On Feb 5, 1:35 pm, "brad" <brad.eckr...@gmail.comwrote:
I'll answer my own post.

The radio buttons didn't change because the IDs were not preserved. I
was depending on the generated IDs, but there are two places where the
question tree is generated:

1. In the init event on postbacks
2. In the load event on postbacks when I detect a user-initiated
change in a dropdownlist which requires a different line of
questioning.

In the inits, the assigned IDs started with ctl0_ ctl1_ etc..
However, in the loads, the assigned ids started with 1 not 0. ctl1_
ctl2_ etc even though I had done a Controls.clear to start with in
both cases.

So none of my postback data lined up with my reconstructed view
state. All I had to do was simply set the IDs in code and life was
good again. Lesson learned: never count on generated IDs when using
dynamic controls.

But it begs this question:

Can I get at postback data that doesn't re-bind to a control ID? Is
it in a collection somewhere or is it buried in the .response?

Brad

On Feb 5, 10:41 am, "brad" <brad.eckr...@gmail.comwrote:
Group,
I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which
contains nested server user controls in order to create a tree-like
hierarchy.
The tree is a sort of question and answer dialog. The user answers a
question, and the next subquestion appears (using dynamic html
display:none|block) depending on his answer.
When all the questions are answered, the webform is posted.
Based on my reading, I understand that I have to recreate the nested
control structure in the OnInit event before the postback data is
applied to my dynamic server controls.
So, I grab my "active" question from the Session state and proceed to
rebuild my tree of controls using a method, appropriately named,
createDynamicControls.
I have verified at the end of the OnInit that the hierarchy is rebuilt
and I'm trusting the IDs to be created the same way, seeing how the
same method is used to always recreate the heirarchy.
Now, I *believe* after the init event, ASP.NET is supposed "fill-in"
the selected values in the form and then fire the page_load events for
the controls. Is this true? Because...
When I inspect my nested control tree in page_load, the state of my
radio buttons is not changed.
Architecturally, I have two custom System.Web.UI.UserControls:
QuestionManager
QuestionItem
QuestionManager has a placeholder on which QuestionItems are arranged.
QuestionItem contains two server controls:
A label for the question text
A placeholder for the answers
Answers are Radiobutton lists of possible answers. For each answer
(radio button list item), there may be a further subquestions.
If there are answer-dependent sub-questions, QuestionItems are created
for them and they are added to the parent answer placeholder
(display:none) and the display is manipulated on the client in
javascript based on the selected answer.
The tree displays nicely on the client, they can select radio buttons,
the appropriate subquestions become visible and life seems good.
--Until the postback.
A. is this a stupid architecture?
B. can it ever work?
C. why doesn't it work? i.e. why are the altered radiobuttons not
ready for me in page_load?
Thanks in advance,
Sorry if this is a newbie question on the wrong group; if it is kindly
redirect me to the appropriate group.
Brad

Feb 7 '07 #3

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

Similar topics

1
by: Joseph Luner | last post by:
I am having problem postback, (code shown below) the variable "my_str" is lost after clicking the "submit" button. Isn't it suppose to display "changed" after posting back? Is there anyway I...
3
by: Big D | last post by:
I have a class that inherits from System.Web.Ui.Usercontrol... all is basically is is a button which is created progammatically such as: public abstract class BaseFrontEndEditor :...
6
by: Andrea Williams | last post by:
When I step through my code, the ASPX Page_Load happens before the Page_Load in the User Control. This means that the property values are not set to their defaults yet in the User Control and all...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
0
by: PeterKellner | last post by:
I have an asp.net 2.0 Image control that I have surrounded with the appropriate atlas:UpdatePanel tags. The Image control referencs an aspx page whose only job is to output an Image. (it forms...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
3
by: ronchese | last post by:
Hello. I wrote a Web Custom Control that have a property named SelectedValue. This SelectedValue property is set after the user clicks a LinkButton control, by its Click() event. I did some...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.