ASP viewstate persistence

  • Thread starter Thread starter Dst
  • Start date Start date
D

Dst

What would be the correct way to do this:

Page A:
ComboBox with values A/B/C
Button which redirects to page B.

Page B.
Button which redirects to Page A.

Start page A, combo box has the value A.
Now if i change the combo box in page A to the value B.
Click on the button which takes my to Page B.
Click on the button which takes me back to page A.

Then the viewstate for the combo has been reset to the value A.

So what are the correct way to handle this persistance ?

And what if i need to return values from page B to page A ?
Like a flag which indicates if page B has been cancelled.
In page A check if page B was cancelled and do different stuff.
How is this done ?

I know i can send parameters to page B like this asp?id=10 etc.
Do i need to do it the same way when sending back to page A ?


What i'm actually are going to do is have a datagrid + 4 comboboxes in
page A.
And a add new record function which will redirect to page B for input
of 6 values.
Then goback to page B and refresh the dataset if page B was not
cancelled.
If cancelled then display the same state for the comboboxes and the
datagrid
as before redirecting to page B.

I'm new to this so need some pointers :).
 
I think the querystring aproach would be the simplest way to go about.
Another aproach would be to use cross-page postbacks, but that would be
a bit messy (you would have to keep the values for the comboboxes
somewhere in page B, and then re-read them from A). Also, the Session
object is an alternative, but I've been taught to stay away from it :P
 
Do you absolutively need to have two separate pages?

Why not use either :

Option 1 :
Code:
<asp:Panel runat=server id=pStepOne visible=true>
... <asp:button runat=server id= btShowStepTwo
onClick='btShowStepTwo_Click'/>
</asp:Panel>

<asp:Panel runat=server id=pStepTwo visible=false>
... <asp:button runat=server id= btShowStepOne
onClick='btShowStepOne_Click'/>
</asp:Panel>

Option 2 : Use the ASP:MultiViews
<asp:MultiView runat="server" ActiveViewIndex="0">
<asp:View>view one </asp:View>
<asp:View>view two</asp:View>
</asp:MultiView>
<asp:button runat=server onclick="btSwitch_Onclick" text="Switch
views"/>

Option 3: create two usercontrols, so you can reuse them on several
pages

Hope that helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top