Link to home
Start Free TrialLog in
Avatar of jml12906
jml12906Flag for United States of America

asked on

asp.net controls losing value after asp button click event

I have buit a questionnaire, and have a problem with the values being cleared after the user clicks on asp button.

This is what I have:
I have 1 form 1 page divided into sections ( step1, step2, step3, etc.) each section (step) is a table enclosed in a <div id="step#" runat="server">
In the code behind aspx.vb page on page load I have

If page.ispostback() then
' do nothing
else
step2.visible = false
step3.visbile = false
etc.
etc
At the bottom of each section I have a asp button btn_continue1, btn_continue2, etc. As a user clicks on the continue button depending on step, the last step will hide and the next step will show using step#.visible = true ( in the code behind).

The problem I have is if a user fills out step2, but then hits the back button to step1 and then hits the continue button to step2; the values they previously filled out on step2 are now cleared.

Why is this happening?
Avatar of neil_squires
neil_squires
Flag of United States of America image

I think this is because of the way the browser works.  When they are on step one and fill out the form, the browser knows what they entered.  When the go to step 2 and fill it out, the browser will know the answeres for page 1 and 2.  However, if the user uses the back arrow, the previous page is loaded, before the values to page 2 were entered.

One solution is to train your users to not use the back button.  Another way would be to set up a different data flow to your page.  Something that comes to mind is the Wizard control.  You can have them step through multiple steps with a familiar look and feel and you can only get to the next page by completing the previous.

Does this help?
Avatar of funwithdotnet
funwithdotnet

If the user is clicking on the browser's Back button, the viewstatealso goes 'Back'. To prevent this from happening, record values to and populate controls from a session variable or alternate mechanism instead of viewstate.
HI,

I think it might have something to do with using .visible = false. Try using a css class where the display property is set to none. e.g.:

<style>
.hidden
{
    display: none;
}
</style>

step2.cssclass = hidden
Avatar of jml12906

ASKER

I tried the control.attribute.add("Style", "Display:none") with no luck either..... I think funwithdotnet is right on the money, I started playing with the populating the controls from a session and that seems to work if lets say i have 2 tabs open 1st tab being the questionnaire and 2nd tab being google or whatever. If I close out of the 1st tab ( questionnaire ) but keep the 2nd tab open and then reopen the questionnaire the values are being populated via session.
I am storing and reloading the session as so:
on continue button click:
Dim qa1 As String = rbl_gh1.Text

' Save to session
Session("sqa1") = qa1
and then on step# load

If Page.IsPostBack() Then

rbl_gh1.Text = Session("sqa1")


End If
But I still have the problem on reloading each step section with the values using  session...Any ideas?
 
ASKER CERTIFIED SOLUTION
Avatar of funwithdotnet
funwithdotnet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help again! Still playing with the session variables to get it right, but I feel you are dead on the money.