473,387 Members | 1,573 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,387 software developers and data experts.

Maintaining state for a programatically loaded control

I've written several UserControls that contain different versions of a form
that users need to fill out. Depending on which role a user is logged in as,
I load the appropriate UserControl and add it to a panel on my WebForm. So
far, so good. However, when the form is posted back to the server, I'm
getting stuck.

I don't think I want to load the control into the panel again because then
all of the values that were set by the user before posting back will be lost.
Still, I have to get an instance of the control somehow.

I thought maybe I'd stuff the entire UserControl into the ViewState (the
user controls are not very big), but then I get an error message saying, "The
type 'ASP.MyDataEntryForm_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate." I've put
a [Serializable] attribute on the control's class, but it doesn't seem to
help. The control only contains other WebControls, all of which can have
ViewState enabled.

Any ideas, or should I go for a completely different approach like
redirecting to different pages instead of loading different controls into a
single page? Thanks!
Nov 18 '05 #1
2 1555
Hi P:

Actually: you DO want to reload the user control on each postback
during the Load event. The controls will pick up the values correctly
from the ViewState and Form elements.

HTH,
--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 20 Oct 2004 00:21:03 -0700, "P. Gruenhagen"
<PG*********@discussions.microsoft.com> wrote:
I've written several UserControls that contain different versions of a form
that users need to fill out. Depending on which role a user is logged in as,
I load the appropriate UserControl and add it to a panel on my WebForm. So
far, so good. However, when the form is posted back to the server, I'm
getting stuck.

I don't think I want to load the control into the panel again because then
all of the values that were set by the user before posting back will be lost.
Still, I have to get an instance of the control somehow.

I thought maybe I'd stuff the entire UserControl into the ViewState (the
user controls are not very big), but then I get an error message saying, "The
type 'ASP.MyDataEntryForm_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate." I've put
a [Serializable] attribute on the control's class, but it doesn't seem to
help. The control only contains other WebControls, all of which can have
ViewState enabled.

Any ideas, or should I go for a completely different approach like
redirecting to different pages instead of loading different controls into a
single page? Thanks!


Nov 18 '05 #2
Thanks, HTH. That worked, of course.

It just seems counter-intuitive to me that you would create a new instance
of the dynamically created control and add it to the page every time the page
is hit. I thought this would've caused the control values set by the user to
be lost. I was wrong.

"Scott Allen" wrote:
Hi P:

Actually: you DO want to reload the user control on each postback
during the Load event. The controls will pick up the values correctly
from the ViewState and Form elements.

HTH,
--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 20 Oct 2004 00:21:03 -0700, "P. Gruenhagen"
<PG*********@discussions.microsoft.com> wrote:
I've written several UserControls that contain different versions of a form
that users need to fill out. Depending on which role a user is logged in as,
I load the appropriate UserControl and add it to a panel on my WebForm. So
far, so good. However, when the form is posted back to the server, I'm
getting stuck.

I don't think I want to load the control into the panel again because then
all of the values that were set by the user before posting back will be lost.
Still, I have to get an instance of the control somehow.

I thought maybe I'd stuff the entire UserControl into the ViewState (the
user controls are not very big), but then I get an error message saying, "The
type 'ASP.MyDataEntryForm_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate." I've put
a [Serializable] attribute on the control's class, but it doesn't seem to
help. The control only contains other WebControls, all of which can have
ViewState enabled.

Any ideas, or should I go for a completely different approach like
redirecting to different pages instead of loading different controls into a
single page? Thanks!


Nov 18 '05 #3

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

Similar topics

1
by: Das | last post by:
Hi all, I'm using Asp.net. Within a form I have declared declared a public variable. When the form is loaded I set the property for the variable. but it doesn't maintain its state on postback. I...
2
by: Jason | last post by:
I have a datagrid inside a user control. I use the itemcreated event to manipulate column values. I then add those values up and place the total in the footer of the datagrid. I have wrapped the...
1
by: Novice | last post by:
Hey all, I have finally managed to create a Custom WebControl and am using a technique from another programmer to maintain state between pages - I would just like to validate this idea. ...
27
by: Raymond | last post by:
They say it's easier, but has anyone tried maintaining an ASP.NET site without the source code of the dlls? This was not a problem with classic ASP, all the code was almost always just in text...
5
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a...
1
by: clintonG | last post by:
I'm having a problem maintaining state with a Panel control in a MasterPage and I need help thinking through this process. The basic structure of the HTML in the Master looks like this... ...
0
by: mark.norgate | last post by:
Hi I'm having a problem in adding controls to a page programmatically in response to a button click. Composite user controls added programmatically in the CreateChildControls() method work...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
3
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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...

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.