Solved

Clearing webform after I refresh after webpage Expires?

Posted on 2007-11-17
9
1,352 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

24 Experts available now in Live!

Get 1:1 Help Now