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
Solved

Clearing webform after I refresh after webpage Expires?

Posted on 2007-11-17
9
1,359 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

828 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