Solved

Clearing webform after I refresh after webpage Expires?

Posted on 2007-11-17
9
1,365 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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