Last post Mar 28, 2011 03:25 AM by mmmundhra
Mar 21, 2011 10:18 AM|MarkBrend|LINK
Can anyone let me know where in the page life cycle and how, I have to take control?
This is what I am trying to do…
I wish to manage my own viewstate so that selection made by the user persist across many pages and are not lost.
My website is made up of 3 pages each page has 3 question
When the user leaves page 1 I store their selections in a datatable and the same for page 2 & 3.
If the user chooses to go back to page 1 then I want to load the ddl with all the option and reselect their original selection.
Hence I want to manage my own viewstate.
What is the best way to achieve this?
Mar 21, 2011 10:24 AM|XIII|LINK
viewstate's only per page and not for multiple pages. Keep it as is.
If you want to keep information from a user over several pages there's a good state management possibility for that already:
Session state. Though I advice against putting large objects like a datatable in any state mechanism. If you only need to keep track of the selected items make use of a list or array or a string or so.
Mar 21, 2011 10:49 AM|MarkBrend|LINK
What I really need to know is how and where to take control in the page life cycle / events to allow me to populate the
Mar 21, 2011 11:02 AM|XIII|LINK
What I really need to know is how and where to take control in the page life cycle / events
Page_Load's mostly the best place to take care of these.
Mar 22, 2011 06:28 AM|Dave Sussman|LINK
You don't really want to take control of view state; what you want is to just load data from the database when the page loads. That maybe what you mean, but it's important to understand that taking control of viewstate means you'd be responsible for encoding
and storing all of the form variables upon page loading and postback.
As stated, just use Page_Load to load the data from the database and set the values of the controls from that data.
Mar 22, 2011 11:12 AM|sirdneo|LINK
What I really need to know is how and where to take control in the page life cycle / events to allow me to populate the controls manually.
Most obvious choice is Page_Load event.
Also look at this article for details on page life cycle. It is very important to understand the page life cycle if you want to take advantage of powers of asp.net.
Mar 23, 2011 12:44 PM|MarkBrend|LINK
Thanks for all you help.
I now have it half working.
what I want to do is simple but hard to explain so I have done a video showing the problem
in short i can get to the values entered in the textboxes but not the dropdownlist
Mar 23, 2011 03:50 PM|XIII|LINK
after taking a look at the video I noticed that in the page_load you always repopulate your dropdownlists. You need to put that piece of code between:
// populate your dropdownlists.
At the moment when you post to the server again and populate your dataset for the table the dropdownlists got repopulated again and as such reset to the first item as being the selected one.
Mar 24, 2011 07:50 AM|MarkBrend|LINK
Thanks for that,
I made a few changes and got it working
protected void Page_Load(object sender, EventArgs e)
// Pull in from session any previous ds
gl_ds = (DataSet)Session["dsUserAnswers"];
// If ds does not exist then create it
if (gl_ds == null)
gl_ds = new DataSet("dsUserAnswers");
gl_dt = new DataTable("dtUserAnswers");
if (IsPostBack == true)
clSaveTbsAndDdlsToDataSet oo = new clSaveTbsAndDdlsToDataSet();
LaidUpFireAndTheftWebReference.clLaidUpFireAndTheftWebService ws = new LaidUpFireAndTheftWebReference.clLaidUpFireAndTheftWebService();
DataSet ds = new DataSet();
#region Load dll's
//Apply setting stored in the ds to the target objects
clLoadTbsAndDdlsFromDataSet o = new clLoadTbsAndDdlsFromDataSet();
Mar 28, 2011 03:25 AM|mmmundhra|LINK
instead of using multiple pages, u can use 1 page and use wizard control. wizard control should have 3 step, in which u can place your respective questions/controls. and everything will me auto maintained in that page viewstate only.