Solved

Clearing webform after I refresh after webpage Expires?

Posted on 2007-11-17
9
1,348 Views
Last Modified: 2013-12-17
I have webform FillData.aspx with two textboxes, a checkbox,  and a Submit button. This is the basic functionality: when I click on the checkbox, it copies the data from one textbox to the other. When I click on Submit, I redirect to page Finish.aspx. Since FillData.aspx expires immediately, when I click the "Back" button in the browser in Finish.aspx, I get the "Webpage has expired" page, which is good.
The problem is that when I refresh the page, not only do I get the data that the user had typed in, it also executes the code in CheckBox1_CheckedChanged.
My question is: How can I clear the typed text after the user refreshes when he clicks on "Back"and sees "Webpage has expired" page?
Here's my code: All my code is server-side. I also tried overriding LoadViewState and SavedViewState, but it didn't work.
protected void Page_Load(object sender, EventArgs e)
{
        Response.Buffer = true;
        Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
        Response.Expires = -10000;
        Response.CacheControl = "no-cache";
        if (!Page.IsPostBack)
                //Clear textboxes
}
protected void Button_complete_Click(object sender, EventArgs e)
{
        Response.Redirect("Finish.aspx");
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
        if (this.CheckBox1.Checked)
                // copy text from one textbox to the other.
}


Thanks.
0
Comment
Question by:MyersA
  • 5
  • 2
9 Comments
 
LVL 1

Expert Comment

by:mmq2006
ID: 20306840
try adding below code within Page Load:
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
Response.Expires = -10000;
Response.CacheControl = "no-cache";
Clear Fields...
0
 
LVL 2

Author Comment

by:MyersA
ID: 20307610
I'm not sure I understand what you want me to do.
I can't clear the textboxes in Page_Load (and out of the !Page.IsPostback) because they'll clear any time the page posts back. For example, the checkbox is set for autoPostBack, so the textboxes would clear out when I click on it.
0
 
LVL 1

Expert Comment

by:mmq2006
ID: 20308040
I meant adding below code to (!Page.IsPostBack) block.
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
Response.Expires = -10000;
Response.CacheControl = "no-cache";
Clear Fields...

also, check below link:
http://jarednevans.typepad.com/technoblog/2005/01/jareds_techno_b.html
0
 
LVL 2

Author Comment

by:MyersA
ID: 20308551
The page doesn't expire if I move the code to !Page.IsPostBack. When I hit the Back button, I'll see all the data.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:MyersA
ID: 20308857
The experts-exchange credit card page also has the same problem. I just bought more points, so I entered my cc#, name, exp. date, etc... I clicked on Submit, and it took me to the Purchase Confirmation page. When I click the Back button, I can still see all my payment information. That's what I don't want.
In my case, when I click on the Back button, I get the standard "Expired Webpage" page. But if I refresh, it'll display all the information I just typed in.

Any help is appreciated. I'm using VS2005 v2.0
0
 
LVL 2

Accepted Solution

by:
MyersA earned 0 total points
ID: 20309235
I was testing the checkbox and I realized that all the textboxes that were typed in after checkbox_checkedChanged are cleared when I click the Back button.
This is what happens:
1. I type something on two of the textboxes, and I click the checkbox to copy the contents to two other textboxes.
2. I type text on a fifth textbox, and I click on a server-side button which redirects me to Finish.aspx.
3. I click the back Button, and this displays the "Webpage has expired" page.
4. I refresh, and the two textboxes that were filled out before I checked the checkbox remain with the text I typed. The other three textboxes (two that were filled with checkedchanged and one that was typed in) are cleared.

Why does this happen?

Thanks.
private bool _isRefresh, _refreshState;
 

protected override void LoadViewState(object savedState)

{

    object[] allStates = (object[])savedState;

    base.LoadViewState(allStates[0]);

    _refreshState = (bool)allStates[1];

    _isRefresh = _refreshState == (bool)Session["__ISREFRESH"];

}
 

protected override object SaveViewState()

{

    Session["__ISREFRESH"] = _refreshState;

    object[] allStates = new object[2];

    allStates[0] = base.SaveViewState();

    allStates[1] = !_refreshState;

    return allStates;

}
 
 

protected void Page_Load(object sender, EventArgs e)

{

    Response.Buffer = true;

    Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));

    Response.Expires = -10000;

    Response.CacheControl = "no-cache";

}

protected void Button_complete_Click(object sender, EventArgs e)

{

    Response.Redirect("OrderComplete.aspx");

    return;

    // OTHER CODE - DOESN'T GET HERE

}

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)

{

    if (!_isRefresh)

    {

        if (this.CheckBox1.Checked)

        {

            this.TextBox_billAdd1.Text = this.TextBox_shipAdd1.Text;

            this.TextBox_billAdd2.Text = this.TextBox_shipAdd2.Text;

            this.TextBox_billCity.Text = this.TextBox_shipCity.Text;

            this.TextBox_billZip.Text = this.TextBox_shipZip.Text;

        }

    }

}

Open in new window

0
 
LVL 2

Author Comment

by:MyersA
ID: 20309501
never mind.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20333952
Closed, 200 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now