473,396 Members | 2,154 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,396 software developers and data experts.

Dynamic Controls on a Multi-Step Form

OK, here's another question for the experts:

I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.

Each panel contains a table which is filled with various radio buttons,
text fields and the such which are built in the code-behind file using
table.rows.add, row.cells.add, cell.controls.add, etc.

Originally I was building all of these either in the Page_Load->Not
IsPostBack section of my code-behind (for the initial panel view) and in
the "Next" button Click event handlers for the panels that followed.

This apparently does not work because the ViewState is not maintained.
Dynamic controls must be created in the Page_Load or Page_Init methods
in order for them to be properly filled with the appropriate ViewState.

So now I have all of these panels being built in the Page_Load method
EVERY time the page is loaded (not just the first time). This
definitely works - I'm seeing the results I expected - but it just feels
wasteful to be building all three panels every time I load the page even
though I am only displaying one at a time.

I'd like to be able to only build the one panel I intend to display, but
since the Page_Load occurs prior to the event handling section of a
page's life cycle, I have no way of knowing which button was pushed and
thus which panel is being requested.

So basically I'm wondering the following:

1. Is there a way for me to determine which button was pushed in the
Page_Load method?
2. Regardless of the answer to #1, am I required to load all dynamic
controls each page load to maintain their viewstate even though I may
not be displaying them this particular page load?
3. If I am required to load all dynamic controls, can you explain how
.NET handles this in an efficient manner as at first look it seems like
a lot of additional processing.
4. What best practices are people using when developing multi-stepped
forms with dynamic controls. We have a ton of projects like these and I
want to create a template to be used for the future.

Thanks for all of your time and patience.

Leo Hart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
3 3933
if you have a fixed set of controls then avoid using dynamically added
controls.

1. i am not aware of this one. though it should be there... i just never
needed to know so never bothered :)

2. you answered your own question.
This apparently does not work because the ViewState is not maintained.
Dynamic controls must be created in the Page_Load or Page_Init methods
in order for them to be properly filled with the appropriate ViewState.
3. the framework goes through lot of steps from IIS passing on a request to
ISAPI filters to actual creation of an instance of the requested page class
for a page's life cycle. it goes through creating the child controls. then
loads the viewstate. then calls page_load then calls the specific event
handler. then renders the output before channelling it across
this blog details a lot of articles by a lot of people
http://weblogs.asp.net/eporter/archi.../15/10109.aspx

msdn article
http://msdn.microsoft.com/library/de...bjectmodel.asp

4. i will leave this one for someone else to ponder. i dont use the above
mechanism it would be wrong of me to answer this.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Leo J. Hart IV" <le******@fmr.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl... OK, here's another question for the experts:

I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.

Each panel contains a table which is filled with various radio buttons,
text fields and the such which are built in the code-behind file using
table.rows.add, row.cells.add, cell.controls.add, etc.

Originally I was building all of these either in the Page_Load->Not
IsPostBack section of my code-behind (for the initial panel view) and in
the "Next" button Click event handlers for the panels that followed.

This apparently does not work because the ViewState is not maintained.
Dynamic controls must be created in the Page_Load or Page_Init methods
in order for them to be properly filled with the appropriate ViewState.

So now I have all of these panels being built in the Page_Load method
EVERY time the page is loaded (not just the first time). This
definitely works - I'm seeing the results I expected - but it just feels
wasteful to be building all three panels every time I load the page even
though I am only displaying one at a time.

I'd like to be able to only build the one panel I intend to display, but
since the Page_Load occurs prior to the event handling section of a
page's life cycle, I have no way of knowing which button was pushed and
thus which panel is being requested.

So basically I'm wondering the following:

1. Is there a way for me to determine which button was pushed in the
Page_Load method?
2. Regardless of the answer to #1, am I required to load all dynamic
controls each page load to maintain their viewstate even though I may
not be displaying them this particular page load?
3. If I am required to load all dynamic controls, can you explain how
NET handles this in an efficient manner as at first look it seems like
a lot of additional processing.
4. What best practices are people using when developing multi-stepped
forms with dynamic controls. We have a ton of projects like these and I
want to create a template to be used for the future.

Thanks for all of your time and patience.

Leo Hart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
I use the same mechanism as you wrote: multiple Panels and user switch panel
visibility to view next/previous step. The biggest form I have is 11 steps
long.

I. My current event model usage.
===========================
I use these event mechanism points to work:

1. in Page_Load you maintain basic activities such as athentication checks
and else
2. the next point is catching events from controls such as
subOnStep1_Go
subOnStep2_Back
onStepCommands("Step1", "Go")
onStepCommands("Step2", "Back")

there you can decide which step to show
process input, store or update data into db and elsewhere
3. Page_Prerender

here you have all events processed
so you can just load updated data from db into selected step
II. Catching user input
===========================

How to catch dinamically added RadioButtons Checkboxes selections

1. You can add checkboxes with clearly identifiable names
and catch their selections in the incoming Form by names
such as:

checkbox[DataRowId]_[WhatToDo]
example:
<input type=checkbox name=checkbox2315_Delete value=1>
<input type=checkbox name=checkbox2316_Delete value=1>
<input type=checkbox name=checkbox2317_Delete value=1>

or

checkbox[StepNumber_WhatToDo] with a value containing [DataRowId]
example:
<input type=checkbox name=checkboxStep1_Delete value=2315>
<input type=checkbox name=checkboxStep1_Delete value=2316>
<input type=checkbox name=checkboxStep1_Delete value=2317>
so the
Request.Form("checkboxStep1_Delete") contains "2315,2316,2317"

when you do like this you can just render controls into Literal or Placeholder
txtStep1Data.text &= "<input type=checkbox name=checkboxStep1_Delete
value=2315>"
txtStep1Data.text &= "<input type=checkbox name=checkboxStep1_Delete
value=2316>"
txtStep1Data.text &= "<input type=checkbox name=checkboxStep1_Delete
value=2317>"
2. You can use DataGrid with row templates
in these templates you define Checkbox control
with an event OnServerChange pointing to your procedure

and, when adding rows to datagrid,
you must specify correct ID of your objects
so you can get it later in your event handling procedure
through Sender object parameters
so, this all works as it is described
I often use the first method cause of it is simplier to make
you just render html string yourself and it is just works

do not forget to switch off Viewstate for an output control
if the rendered text grows up too large
"Leo J. Hart IV" <le******@fmr.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
OK, here's another question for the experts:

I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.

Each panel contains a table which is filled with various radio buttons,
text fields and the such which are built in the code-behind file using
table.rows.add, row.cells.add, cell.controls.add, etc.

Originally I was building all of these either in the Page_Load->Not
IsPostBack section of my code-behind (for the initial panel view) and in
the "Next" button Click event handlers for the panels that followed.

This apparently does not work because the ViewState is not maintained.
Dynamic controls must be created in the Page_Load or Page_Init methods
in order for them to be properly filled with the appropriate ViewState.

So now I have all of these panels being built in the Page_Load method
EVERY time the page is loaded (not just the first time). This
definitely works - I'm seeing the results I expected - but it just feels
wasteful to be building all three panels every time I load the page even
though I am only displaying one at a time.

I'd like to be able to only build the one panel I intend to display, but
since the Page_Load occurs prior to the event handling section of a
page's life cycle, I have no way of knowing which button was pushed and
thus which panel is being requested.

So basically I'm wondering the following:

1. Is there a way for me to determine which button was pushed in the
Page_Load method?
2. Regardless of the answer to #1, am I required to load all dynamic
controls each page load to maintain their viewstate even though I may
not be displaying them this particular page load?
3. If I am required to load all dynamic controls, can you explain how
NET handles this in an efficient manner as at first look it seems like
a lot of additional processing.
4. What best practices are people using when developing multi-stepped
forms with dynamic controls. We have a ton of projects like these and I
want to create a template to be used for the future.

Thanks for all of your time and patience.

Leo Hart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #3
Thank you both for your responses!

From the sound of the first answer, it seems I may be required to build
all of these dynamic controls each load, regardless of whether they will
be displayed. I would like to figure out if you can determine which
button was pressed in the Page_Load method.

On the second answer, although I can see how using plain html controls
and Request.Form would work, I'd really like to make use of the new
features in ASP.NET. For instance, I need to know if a particular
control is enabled or disabled and it's much easier (and cleaner) to
modify/reference a controls properties via an ASP.NET control. The
datagrid approach might be worth looking into, but won't I still have
the same problem when I process form postings? Won't I still need to
create the controls each load to reference them?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

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

Similar topics

3
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to...
0
by: michelle | last post by:
I am experimenting with dynamically creating pages containing custom controls in response to http requests caught by an http handler, in place of writing and requesting aspx files. Specifically, I...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
0
by: pbb | last post by:
I have a web page on which I dynamically create controls based on the selection a user makes from a dropdownlist (this ddl is not dynamic). Depending on the user's selection, the controls could be...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
1
by: Diffident | last post by:
Hello All, I am trying to add dynamic controls onto my page and here is how I am doing that. I have a page which has a button called as "AddMoreControls" and in this button's event handler I...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
3
by: hhendrickx | last post by:
Hello, I have a problem showing a multi-line client-side messagebox. Single-line works ok but multi-line does not. How can I show multi-line client-side messageboxes? Code: String message =...
4
by: mbrunell | last post by:
Hi, Under AIX, I have created a script which is checking URL status. Problems come when I want to check HTTPS URL status... To have my script working with HTTPS URLs, I must set the LIBPATH...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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,...
0
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...

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.