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
Similar Messages:
Mar 27, 2010
I have four dropdowns in the first page and then a button which saves the selected values from the dropdown to a session state .
In the second page I do have previous button which comes to the first page. My problem is that the dropdown values are not getting preserved.
Here is my code for the First page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyBusinessLayer;
using MyDataLAyer;
[Code]......
The problem is that I get the error object instance not set to an instance of an object
View 3 Replies
Feb 9, 2010
I've a checkbox with autopostback=true. If i check the checkbox the postback occurs and changes a label text. But if i click back in the browser the checkbox is not returning to its previous unchecked state. How can i bring back its state?
Can i write some JavaScript to persist the state of a control?
View 1 Replies
Feb 17, 2010
I'm writing an ASP.Net application (no AJAX, but maybe) and there's a requirement to have a list of companies graded under a traffic light system. I intend to have these in a collapsible hierarchical list on the Master page, e.g. Red expands to show companies, and then companies can be further expanded.
how can I keep the expanded list in the same place, with the same content visible, between page loads?
View 1 Replies
Dec 3, 2010
How to implement caching to a dropdown list
View 2 Replies
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
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
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
Aug 11, 2010
I am having a dropdownlist and fill it by providing dataset its working on page now what i want is when i am click on a button page is transfer to another page but from that page when i am back i want dropdown value selected.
View 4 Replies
Mar 5, 2010
1) I found that my viewstate was not being persisted across postbacks for web user controls. I ensured that the Enable Viewstate property was set to true (of the page)
2) The Viewstate isnt being persisted on the 1st postback.
3) However, it is being persisted from the 2nd postback onwards.
I stepped through the code to ensure that the Viewstate had the 2 keys that I was adding on page load. However, on the 1st postback, the viewstate is empty. Everything is ok from the 2nd postback onwards.
[Code]....
View 3 Replies
Feb 5, 2011
I am having tough time finding out this reason. I have a web control where i add some variable in viewstate. like viewstate["test"] = "1".
when i post back this viewstate no more exists in collection.
[Code].....
View 1 Replies
Apr 4, 2011
Alright, so here's my basic ASP.NET page setup: I've got a page with a GridView that has ContentTemplates in it. You can add a row and edit/remove rows at any time. There's a "New" button that creates a new row.
All of this data is bound to custom data objects. So if I have a GridView of "People" and each row has "FirstName", "LastName", and "Gender" (with TextBox and DropDown controls), I then have a "Person" object which has public properties for "FirstName", "LastName", etc. I have the binding set up correctly, and I can push data into the GridView from the object, and I persist the object with the Session variable. My page lifetime structure looks something like this:
Page_Load: Loads the List(Of Person) from Session()
Any events fire, and modify the List(Of Person).After any event, the List(Of Person) gets saved back into Session(), and is then DataBound to the GridView (and any subsequent fields are also DataBound, such as the DropDownList.
My question is: Whenever I fill in rows in the GridView, and then add a new row (there is no database saving going on whatsoever), my fields clear out and don't persist across PostBacks. So, how can I persist my custom data objects with databinding across postbacks?
View 2 Replies
Apr 12, 2010
I'm having troubles remembering how to grab the list view's state, or page, so that when you leave the list, you can return to the list view page you left on. I have a data pager, and I have hyplerlinks for items in the list view that take you to a file upload or file delete page, and then returns to the list view. It returns to the list view's initial state (first page).
View 1 Replies
Jul 9, 2010
At present i am able to persist that using session InProc mode. except that i cant use either stateserver or sql server as the HTTPPostedFile is not serilizable. i can't use viewstate either for the same reason. Is there any work around to persist that httppostedfile across postbacks for session modes other than inProc or viewstate?
View 4 Replies
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
Jan 14, 2010
1. I have couple of checkboxes and some text fields outside the updatepanel.
2. Based on the checkbox selection, I will be hiding/showing the fields to user using javscript.
3. I have a upload control in the same page which is placed under the updatepanel. When I upload the file, I will be reading the content of the file and I'm trying to load it into the controls which are outside the updatepanel. As I know the controls won't updated until unless it has been added under the updatepanel.
4. I moved all the controls outside the udpatepanel (checkboxes and textboxes) and placed it inside the updatepanel so that when the file is uploaded I can read the file and assign to the controls.
After this, I was able to assign the values to the control. However, the problem is, the state of the page (javascript hide and show) has not been retained during the postback. For example, if i have 2 checkboxes and 2 textboxes, if i click firstone, it should show the first checkbox. If I click the second checkbox, it will show the second textbox. By default, when the fresh load happens, first textbox will be shown. When I click the second checkbox (its showing the second textbox) and do the postback by uploading the file, the state gets lost and when the page load completes, it's showing the first textbox instead of showing the second textbox.
View 3 Replies
Oct 6, 2010
I wanted to know the best practice for caching data. Say I have some control example a dropdown list which is populated from my db. Now this dropdown is global and used across many pages. I was thinking of not going to database everytime to fetch data for this dropdown and put the result in Cache. And then populate this dropdown from cache. Is this a good practice or if there is another approach. Can I store my datareader in cache and then use it globally. Also could I do this in application start event?
View 4 Replies
Dec 30, 2010
I have created a matser page with a two radio buttons, text box and a button. Whenever user sets some values to these control and clicks the button, i will navigating him from one content page to another based on the data he has entered. The problem is after the content page load, the values selected/given in the controls(radio button, text box) are getting cleared.
Is there some way to maintain the values ?
View 8 Replies
Jul 23, 2010
I have a web form with a whole bunch of drop down lists (mainly) that works perfectly well and has been for some time. However, we've found a scenario that seems to corrupt the viewstate of this form in someway, or cause it to lose it's viewstate. The problem occurs when the user has this form displayed, then clicks on a link that opens up another window. A few more steps to open up a second and third window, followed by a write to the database. Then the user closes these windows down, leaving this original window open. At this point, the user selects something from one of the dropdowns. And the app crashes because the dropdowns have lost all of their values (and so a bit of code that is trying to work with one of the ddl's selectedvalues fails).
When the user selects this dropdown, the page_init event fires, followed by the page_load with postback = true. The dropdowns themselves are defined in the aspx page markup, but the values of them are generated and added in page_load (where postback = false). I've relocated the code to populate these controls to the page_init code and now the app doesn't fall over, because the values are re-populated. However, all of the selectedindexes are being reset, so the original values are lost and the screen redraws after this postback with all of the dropdowns reset.
View 1 Replies
Nov 18, 2010
i have a form on page1.aspx with several controls (textbox, dropdownlist, etc).on Page1 PageLoad event i load data from database and performe databinding.From Page1 a user can, by clicking a specific button, move to Page2.aspx to insert some details and, after saving details, he returns to page1.
if save changes are made on control on page1 before save them to db, obviously, these are lost on return from page2 (because are reloaded on pageload from db).How can i save control status between pages round trip?
View 3 Replies
Nov 19, 2010
I want to add a list to the cache and I would like it to stay there as long as posible.
Is there a way adding something to the cache permanently?
how do i set the exiry date of a cached object?
View 6 Replies
Sep 8, 2010
Does anyone know how to do this so when I select something the 1st dropdown and the 2nd one becomes visible and populates list from a Select statement. I really need help on how to do in an aspx and not on the code behind page.
View 12 Replies
Jun 3, 2010
I want to make a cookie that contains a list and then i want to be able to get the information from the list by entering the list items specific key value. I quickly made a test application to see if it works or not and the code that im posting below is Not working
[Code]....
View 7 Replies
Jan 31, 2011
I stored a list<mytype> object in a viewstate. Type of list<mytype> comes from a public structure which is defined at page.
When I try to convert viewstate to a list<mytype> object it cause error.
Public struct mytype
{....}
Page_load()
{ list<mytype> obj = new list<mytype>();
viewstate["mystate"]=obj
}
My_function(){
list<mytype> tempobj = new list<mytype>();
tempobj = (list<mytype>)viewstate["mystate"];// this line cause error !
}
View 5 Replies
May 27, 2010
I want to store List<Class> object to ViewState, when i try to do this than its giving me error to make class serialize,but my class is partial class so didn't get serialize keyword on class how can i store List object to viewstate.
View 4 Replies