473,713 Members | 2,494 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 3979
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
6829
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: DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new Size(95, 20),...
0
1646
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 some business processing - instantiating the Page class and adding controls - rendering the page...
5
2419
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
2093
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 load_page event again. The questions display and function perfectly. The user anwers the question...
0
1341
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 can know what type of control to render and what items to put in the ddl etc. My problem is that I...
3
1857
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 & " these events" & dtrCal(1) lbtnCtrl.ID = "wecc" & i.ToString
1
2200
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 controls are added properly. However, if I click the "AddMoreControls" for the second time the...
9
3627
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 can't know what dynamic control I have to create.
3
1596
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
2967
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
8795
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
8701
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
9306
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
9168
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
9009
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...
1
6621
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...
1
3155
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
2510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2103
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.