473,573 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.a dd, 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 3960
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.c om> wrote in message
news:OV******** ******@TK2MSFTN GP14.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.a dd, 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=checkbox23 15_Delete value=1>
<input type=checkbox name=checkbox23 16_Delete value=1>
<input type=checkbox name=checkbox23 17_Delete value=1>

or

checkbox[StepNumber_What ToDo] with a value containing [DataRowId]
example:
<input type=checkbox name=checkboxSt ep1_Delete value=2315>
<input type=checkbox name=checkboxSt ep1_Delete value=2316>
<input type=checkbox name=checkboxSt ep1_Delete value=2317>
so the
Request.Form("c heckboxStep1_De lete") contains "2315,2316,2317 "

when you do like this you can just render controls into Literal or Placeholder
txtStep1Data.te xt &= "<input type=checkbox name=checkboxSt ep1_Delete
value=2315>"
txtStep1Data.te xt &= "<input type=checkbox name=checkboxSt ep1_Delete
value=2316>"
txtStep1Data.te xt &= "<input type=checkbox name=checkboxSt ep1_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.c om> wrote in message
news:OV******** ******@TK2MSFTN GP14.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.a dd, 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
6814
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 figure out, if there is a way of using polymorphic way (if that is a word) of doing this particular property. A sample of my code is as follows: ...
0
1644
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 am doing the following: - mapping requests to an http handler - instantiating a class hierarchy that, retrieves data, parses the URL and performs...
5
2397
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 control (.ascx).
4
2079
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. Each question is displayed and answered, then result written to a SQL table. Then the next question is read from a table and displayed using the...
0
1332
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 any combination of textboxes, ddls, popup calendars, etc. The properties of the dynamic controls are stored in a SQL database so that my program...
3
1848
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 LiteralControl Dim lbtnCtrl As New LinkButton ltrCtrl.Text = "<br>" lbtnCtrl.Text = "WE: " & dtrCal(10).ToString lbtnCtrl.ToolTip = dtrCal(10).ToString & "...
1
2181
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 am creating controls dynamically and adding them to a panel on the page. For example, if the button is clicked once, the page is posted back and the...
9
3613
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 to create the dynamic controls in the OnInit stage of the lifecycle. Since data from static controls is not yet available in the OnInit stage I...
3
1594
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 = ""; message = ers.Tables.Rows.ToString(); link.OnClientClick = "return confirm('" + message +"'),false;"; tc1.Controls.Add(link);
4
2957
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 variable correctly : # LIBPATH=/opt/freeware/lib # ./check_url.pl https://myexample.com SUCCESS
0
7784
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...
0
8205
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...
1
7796
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...
0
8074
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...
1
5601
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...
0
5294
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...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1044
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.