?
Solved

Clearing webform after I refresh after webpage Expires?

Posted on 2007-11-17
9
Medium Priority
?
1,369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

800 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