State Management :: Dynamically Loaded Controls In Init But Viewstate Not Persisting

Jan 20, 2011

I read this article first to try to solve this issue, but I am already loading the controls in the Init phase of the page, yet viewstate is not persisting. Any ideas as to why? (Of note is that this is for a custom module in DNN and I do have some AJAX update panels on the page, though this section is not within an update panel, for what it's worth.)

As an overview of what I've got:

1. LoadControl.ascx - based on reading query string parameters, determines whether to load the master or the detail .ascx.
2. Master.ascx
3. Detail.ascx

In my master control I dynamically load either a master or detail sub-control in the page_Init. The detail page has a treeview control and then uses a multi-view control to display the panel associated with the depth of the node selected on the tree. On the panel being displayed I have a cascading ddl within a detailsview control which initiates a postback to select the child ddl based on the parent ddl selection. However, when the page refreshes after the postback, both ddls have resorted to their default selection.

What is interesting however, and I just realized this as I am typing, is that the Treeview is populated when the page comes back from the postback, so that is only possible if viewstate is being persisted right? (See the page_load code and you'll see that Call PopulateRootLevel(intTreeUserID) which populates the treeview, is not called on postbacks....hmmm.

Any ideas as to why the treeview maintains viewstate but not my ddls???? But though the tree is populated, I do have to explicitly select the node again and set the panel that the detailsview control is on to visible again too....

Here is the dynamically loaded control code:

[Code]....

And in the Detail.ascx page load I've got:

[Code]....

[Code]....

View 6 Replies


Similar Messages:

State Management :: Viewstate Error After Refreshing Page With Dynamically Loaded Controls

Jan 14, 2011

I have a page that loads a usercontrol dynamically. Depended on the user's actions, this control may be unloaded in Page_PreRender and a different control may be loaded instead. I am attempting to use the solution outlined by Mark DotNet Evans in this post:
http://forums.asp.net/p/1491790/3814320.aspx

This all works great, except if the user clicks the refresh button in the browser just after the change of usercontrol. Then, I get an error

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. ...

I assume the error is caused by the browser re-posting the request with the old viewstate that matched the control tree when the page was loaded, but no longer does. How can I prevent getting an error when the user reloads the page?

View 6 Replies

Persisting Dynamically Loaded User Controls In View State?

May 13, 2010

I have a simple user control containing two text boxes which I am adding to placeholder on Button Click event. I am storing the number(count) of clicks in View state and running a loop using count to create all previously added user control. I am also adding IDs to each User control (appending "UC" and count). I have also checked in view source the ids are same each time they are created. I have another button which basically does an post back. I have EnableViewState enabled ="true" in all controlls all the way up to Page Level. My problem is that User Input does not persist on postback. Should this not be happening automatically for me?

View 2 Replies

State Management :: Failed To Load Viewstate. The Control Tree Into Which Viewstate Is Being Loaded Must Match ?

Oct 9, 2010

Now here is the weird thing. First i am running it locally on the built in vs2008 web server.I load my control in fine, do a postback from a linkbutton, locally on my machine it all works fine, no issue.However when it goes onto my host, it falls over with the message:

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.Now i also load controls dynamically and use postbacks and things in the admin area of the site...and that works fine, however my front end just keeps failing? See the code behing below:

[Code]....

View 1 Replies

State Management :: Dynamically Added Controls And 'Failed To Load Viewstate' Error

May 23, 2010

I am writing a search results page for an airline booking system. I have Next/Previous buttons to view flights for the next or previous days. The way i have done my results grid is that i use an HtmlTable and dynamically add rows, cells and controls into the cells. This gives ultimate flexibility given that we can add any control type we want and have it function as it does everywhere else in the system. As you should be aware - i must recreate these controls each time the page is reloaded (in the page_init event) since asp does not handle this automatically.

When they go next/previous it refreshes the flight data and re-populates the grids. If they select a flight in the return grid (by checking the RadioButton), and go next on the FIRST leg grid, the selection of the return leg stays the same after the postback
- which is great. But the problem is, if the flight they selected on the return leg is no longer available it will not create the control and i get the following error;

"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."

Is there any way to tell asp.net that if you do not find the control anymore, simply ignore it rather than throwing the error? The nature of this design is that there potentioally WILL be a different layout after the page is posted back.

View 7 Replies

State Management :: How To Custom Controls And ViewState Management

Aug 24, 2010

I want to know that when we create custom controls, then is there State Management through ViewState done automatically or we have to handle it explicitely ?Since i have created Custom Controls that is behaving as if it is not maintaining its state on PostBack.

View 9 Replies

State Management :: Persisting A Class Object?

Nov 5, 2010

I wish to persist a class object across postbacks by using a single session variable/object/whatever.

The class has about a dozen single variable properties; and about a dozen table properties; and several methods. The main table tracks rows of sporting event results. The web site will collect one row at a time for each postback. The data in the object's constructor is based on a dataset, but the data in the class will grow each time I do a postback so I don't want to loose the information in the class. The data isn't very big - it will fill a single computer screen.

Being new to programming I am thinking that I can store the dataset in the session but that would slow down the response time because I the methods would have to be called to refine the data - or maybe I can just store the entire class object in a session.

View 3 Replies

C# - Viewstate With Dynamically Loaded Control

Feb 16, 2011

I am having issues with my dynamically loaded control's events.Here is how I am loading the control:

protected void Page_Load(object sender, EventArgs e)
{
LoadSubPageEditTemplate();
}
protected void LoadSubPageEditTemplate()
{
pnlPageTemplate.Controls.Clear();
BaseOfferAdmin adminControl = (BaseOfferAdmin)this.LoadControl("~/Controls/SingleOfferAdmin.ascx");
if (adminControl != null)
{
adminControl.ID = "Control_ID"
pnlPageTemplate.Controls.Add(adminControl);
}
}
}

The LoadSubPageEditTemplate() is also fired from a button event on the page, since I have to update it after the button event has executed.

The control loads perfectly, I have tested it with a basic button and the postback fires as expected. However, I am getting weird results with CheckBoxes.

<asp:CheckBox runat="server" ID="cbOptionalAction" Text="CheckBox" AutoPostBack="true" OnCheckedChanged="cbOptionalAction_CheckChanged" />

The CheckedChanged event only fires when the Checkbox is checked, which I guess means there is some issue with my control viewstate. If I have multiple checkboxes on the page, and one creates a postback, the checkchanged event is fired for each checkbox that is checked.

View 1 Replies

State Management :: ViewState And ObjectDataSource / Getting Values From Viewstate In GetTopThemes?

Jan 11, 2011

I have problem getting values from viewstate in GetTopThemes.

<asp:ObjectDataSource
ID="sourceGetTopThemes"
runat="server"
TypeName="DBConnection"
SelectMethod="GetTopThemes"
EnableViewState="true"></asp:ObjectDataSource>

[Code]....

}

[Code]....

when the page is not Posted back, I saved all values in the viewstate.

View 2 Replies

State Management :: Persisting The Cookie Across Development And Production Server?

Jan 2, 2011

I am using this code to pass variables from ASP.NET application to HTML Application:

[Code]....

The above code is run from page_laod event, and I am making some development changes on the Development Machine (say
http://eutdev02/ehrmd).

After the ASPX page is loaded, and I debug the javascript in the HTML (F12 under IE8), and can see the Cookie is found in the browser.

But, when I open the target HTML/Javascript web page (which will read the cookie prmStaffID), but the HTML Page is on the production machine (separate server say

http://prod01/Attendance.html), the Cookie is not found !!!

It seems to me that Cookies will persist only on one IIS Server, and will not be global.

Question:How I can persist the Cookie on the Client Machine regardless of the the Server Machine ?

For testing purposes, I want to send the cookie to the client from teh Development Server, but the target application is under HTML/Javascript, and I want to be able to read the same Cookie using Javascript.

View 5 Replies

State Management :: ViewState - Does The Master Page Have Its Viewstate

Apr 30, 2010

I have been getting this error a lot lately with some of my users, and I had a couple of concerns with view state and I have read so many articles but I am still lost..

1. I use masterpage on all the pages and I need viewstate for some of the pages but..

There is a page where a user will fill out the information and then submit this data to a cgi server, and it is where I get most of the Client Disconnected errors, what would happen if I disable viewstate when they click on that button?

Now when a user browses from one page to another, does the view state from the previous page get deleted? If not how would I delete it?

Does the master page have its own viewstate? Would I be able to make sure none of items on my master page are using the viewstate?

View 7 Replies

State Management :: Persisting DropDown List Attributes Across Page Postbacks?

Oct 12, 2010

how can DropDownList attributes be persisted accross page Postbacks?

Example:

DropdownList1.AutoPostBack = True
DropdownList1.items(0).Attributes.Add("Attribute1","somevalue")

On Postback the attribute is no longer available (ie. attributes.count=0).

I tried persisting using the code below, but was unsuccessful:

Before PostBack: ViewState.Add("DDL","DropdownList1")
On PostBack: DropdownList1 = ViewState("DDL")

This generated the error: DropDownlist is not marked as serializable.

I than tried:

Before PostBack: Session.Add("DDL","DropdownList1")
On PostBack: DropdownList1 = Session("DDL")

This did not err but attributes were still not available.

View 4 Replies

C# - Viewstate Variable Lost On User Control Loaded Dynamically

Feb 12, 2010

I have a problem with ViewState. I have an aspx page that has a treeview on the left and an UpdatePanel with an ASP.NET Panel inside on the right. It is in that inner Panel where I load and unload dynamically user controls. I use that update panel to load dynamically controls.

I also made a custom control for my user controls because I need to pass some values from page. On that constructor I use ViewState to store these values.

The first time I load the user control I call its constructor with parameters. When I reload that user control on each postback I use its normal constructor.

My problem is I the values I've stored on ViewState has become null on successive postback.

Update:

This is a piece of my user control:

public class MyUserControl : System.Web.UI.UserControl
{
private int PKId
{
get { return ViewState["pkId"] as int; }
set { ViewState["pkId"] = value; }
}
public MyUserControl(int pkId)
{
this.PKId = pkId;
}
...
}

I'm following this article to load controls dynamically: http://msdn.microsoft.com/en-us/magazine/cc748662.aspx#id0070065.

Second Update:
I also set the same control ID when I load the user control at first time and on each reaload.

Maybe I can use another method to store these values like input hidden fields or Cache. I've choosen ViewState because I don't want to overload server with Session values for each user.

Third update:

I load the controls with this code:

System.Web.UI.UserControl baseControl = LoadControl(ucUrl) as System.Web.UI.UserControl;
if (baseControl != null)
{
baseControl.ID = "DestinationUserControl";
PanelDestination.Controls.Add(baseControl);
}

And reaload with this code:

DynamicControls.CreateDestination ud = this.LoadControl(TrackedUserControl) as DynamicControls.CreateDestination;
if (ud != null)
{
ud.ID = "DestinationUserControl";
PanelDestination.Controls.Add(ud);
}

View 4 Replies

State Management :: Create And Strore Controls In Viewstate?

Dec 20, 2010

Currently I am creating some dynamic controls on my page these can be hundreds of controls.Some of these will be available depending upon the input of the page so you can say the visibility will be different. This page in fact represents the dozens of pages.I want to create these pages from viewstate, e.g I have created 5 textboxes on page_Init() and then want to store these in Viewsate and next time if needed then load from the view state.In the other words can I create the and store the whole control object with all of the properties in viewstate, if so then how I will be able to accomplish this.

View 2 Replies

State Management :: Stop Viewstate To Mapping To Controls ?

Jul 29, 2010

I want viewstate to stop showing its magic at particular event in my page. Problem details is :I creating dynamic panel on my page_init event ( added to parent panel on aspx ) and creating dynamic dropdown control on page load events with values 1,2,3,4,5 in which 1 is default and added this dropdown to panel i created in init event. As my controls are dynamic , I am creating these controls on postback also. I had enable viewstate property true for all controls as I want them to persist user data on postbacks. i.e. if after page gets loaded drpdown default is 1 and uses select 5 and click on any button on my form ( Postback ) dropdown should show 5 and this is working for me. But problem in one requirement is one particular after button click event on my page say ( Reset) i want my dropdown value should not persist user selection and should display default value 1. I can t reset my controls on this button click event. All I want is as these are my dynamic controls , they are created on every page_load and fresh data is loaded, on particular REset button I want my Viewstate should not map to my dropdown. and controls should show whatever default selection is.

View 1 Replies

State Management :: Maintaining Viewstate On Gridview With Controls?

Jan 14, 2011

I have a gridview with results from a database query and columns where I add linkbuttons to individual cells.

something like:

Dim LB2 As New LinkButton

LB2.Text = "title"
LB2.CommandArgument = "argument"

AddHandler LB2.Click, AddressOf LaunchDocument

GridView1.Rows(i).Cells(10).Controls.Add(LB2)

There is a lot time involved in determining what cells get the linkbutton and I want to avoid going through that process on a postback when a user clicks one of the linkbuttons.How can I maintain these controls in the gridview after a user clicks a linkbutton and a postback is done?Right now the application has to go through the process all over again.

View 6 Replies

State Management :: Web Controls In Collapsible Panel Does Not Maintain Viewstate?

Jul 23, 2010

I have a search page containing a collapsible panel with several controls including text, radio, drop list and check box. In the same page there is a gridview to display search result and links to other pages.Everytime I click on a link in the gridview, the viewstate is only maintained if I nevigate with the pagination of the gridview. However if I click on a link in the gridview and click the back button to the search, everything goes back to default, and the search results will be gone from the gridview. How may I enable the controls and the gridview to remain the same if I hit back button to it?

View 3 Replies

State Management :: Stopping ViewState Persistence On Dynamic Controls?

Oct 15, 2010

I have a set of dynamically-created (IE: by code) controls on my web page. Depending on which options the user decides to go (Edit/New), those controls are re-created with the appropriate information (IE: "with values" with Edit, "without values" with New).

Here's the situation:

- I create my controls in InitComplete when it comes to save the data (both on Edit/New) contained within the controls.

- I create my controls in PreLoad when it comes to load them initially (Both on Edit/New) in order to avoid the ViewState to kick in.

However, despite creating the controls after the ViewState has been applied (technically), the controls still somehow retain the pre-postback's information. IE: if I have options 2 and 4 selected and I choose "New", which should show the options without being selected, they remain selected no matter what. And this is true despite changing their values in the PreLoad state. From my understanding, creating a control in this fashion and at that point in the page lifecycle should override any values the ViewState might have had for those controls. I have also tried to disable the parent's control viewstate (Table.EnableViewState = false) again, to no avail.

I've tried using the Me.ViewState.clear() and Me.ClearChildViewSate prior to loading the initial values as well, but again all for naught. I do understand that any control created after the Init phase of the lifecycle has to play "catchup" with the current state, however I would expect that clearing the ViewState prior to creating the controls would fix this issue. It doesn't seem to.

View 1 Replies

State Management :: Reload Page Only Once After Being Loaded From IE Favorites Tab?

Nov 3, 2010

I have a page with several panels which are enabled or disabled depending from which page user were redirected to this particular page (based on UrlReferrer). Everything works perfectly until a user adds this page to favorites in IE8 (not sure about other browsers at this point), and then returns to that favorite in the future. It contains the previous data and not the data from the current page . When I click F5 it works again becase page is reloaded from the server and not from IE cache. How can I avoid this issue? Is there any way to force page reload only once! I tried also to put some code into "If Not IsPostBack", but it still does not work.

View 3 Replies

State Management :: Session Variable Persisting Even After Abandoning A Session - Closing Browser Windows

Aug 5, 2010

I have been spending a better part of a week trying to track down why I am not able to clear all session variables in a web app (vs 2010, vb.net). What I have tracked it down to is that when I remove or abandon sessions that my html pages or codebehind access, it works, but for some reason in any of my class files where I use "Public Shared strConnection as String = HttpContext.Current.Session("strConnection").ToString" to access a session variable, it finds the old one and not the current one. I have to wait for it to time out, go in again, and it will find the new one.

I do not use Linq, and there is only one place in the whole web app that I place the connection string in a variable whcih is when a person logs in. It points them to the correct database. The sqlconnection is set for all of my listviews in Page_Init to make sure that they aren't using any session variable that they create on their own. Interestingly enough that if I use debug to go in each time, exit debug, enter debug again trying to access a different database, it works correct each time. I assume that debug is correctly killing the session variable for the classes for me.

View 4 Replies

State Management :: Bug In .NET ViewState

May 20, 2010

I start with a blank ASP.NET page where I disable ViewState for the whole page with EnableViewState=False and even ViewStateMode=Disabled.keep adding various controls to the page -- Label, Table, Calendar, TextBox, DropDownList.Everything looks good, i.e. my __VIEWSTATE tag fluctuates between 24 and 28 characters.As soon as I add a single RadioButton (or CheckBox), the __VIEWSTATE shoots up to 130 characters. And it keeps growing by over 100 characters every time I add another RadioButton.

View 19 Replies

State Management :: Set A Certain Viewstate To Nothing?

Apr 19, 2010

I have a code like this in the Me.LoadComplete event.

[Code]....

Now I would like to set this viewstate("data") = nothing on a certain button click in a user control (.ascx) in this page but it doesnt clear the viewstate. What am I doing wrong? In the onClick even of the button in the .ascx I write Me.viewstate("data") = Nothing

View 4 Replies

State Management :: Viewstate / Use Textbox Value?

Jul 22, 2010

I want to use textbox value after I visit from current to other page then again to current page using viewstate but value should be the one when I was current page last time.

View 3 Replies

State Management :: ViewState Value Set After 2nd Postback?

May 3, 2010

I am creating a simple string of values that get added to a label after a post back. I am setting the values thorugh ViewState. However, my appended values do not get updated until AFTER the 2nd postback. Example:

On Page_Load the label displays a "0";

If I enter a "1" in the text box and click the button the label still displays a "0";

If I click the button again (the 2nd postback) then my label correctly displays "0,1"; This works for whatever value I enter after. i.e. "0,1,35,hello world", etc.

What I am I missing? Code Below.

.ascx - I left out inherits and codebehind

[Code]....

View 4 Replies

State Management :: Pop Up Change Viewstate?

Dec 22, 2010

have some viewstate value in my opener window ,when i close the popup i want to set new value in the opener viewstate.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved