By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Page Refresh issue

P: n/a
PK9
I'm having an issue with the "Refresh" of an asp.net page. The refresh is
actually calling my last onClick event. I thought that asp.net was supposed
to be stateless in that it shouldn't remember that I clicked a button before
the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load event
hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need to
check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save" onClick="btnSave_Click"
/>

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9
Nov 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Firs you have understand what postback really does. Simply: when you click
un a button causing postbact, javasript stores this information in some
hidden fields in pages form (__EVENTTARGET, eventartgs ....) and POST the
form to server. When server handles request, parses this values and when
find right value, process the event handler. When you click Refresh, browser
will send again the same data as before, so your handlers are executed
again.

You can add some hidden field with for example Guid or datetime, and when
you wil be processing request with same guid again, you know that user
refreshed the page
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh is actually calling my last onClick event. I thought that asp.net was supposed to be stateless in that it shouldn't remember that I clicked a button before the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load event hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need to check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save" onClick="btnSave_Click" />

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9

Nov 19 '05 #2

P: n/a
PK9
I'm not sure I unserstand everything, but what it sounds like you're saying
is that the page refresh is functioning correctly. Is that true? Is it true
that the onclick event handler which was last initiated will again be
initiated on a page refresh? Maybe I'm wrong, but I was told by others that
ONLY the Page_Load should be kicked off when I refresh the page, not the
Page_Load + the event handler.

I've tried to use hidden fields to store a text value indicating that a
"page mode". I set the hidden textboxes value to something after save is
clicked (thinking I'll be able to check for it again at the beginning of the
onClick event handler). However, when refreshed, the origninal value (empty
string - "") is returned. The page refresh grabs what "WAS" stored in the
textbox, not what "IS".

"Jakub" wrote:
Firs you have understand what postback really does. Simply: when you click
un a button causing postbact, javasript stores this information in some
hidden fields in pages form (__EVENTTARGET, eventartgs ....) and POST the
form to server. When server handles request, parses this values and when
find right value, process the event handler. When you click Refresh, browser
will send again the same data as before, so your handlers are executed
again.

You can add some hidden field with for example Guid or datetime, and when
you wil be processing request with same guid again, you know that user
refreshed the page
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh

is
actually calling my last onClick event. I thought that asp.net was

supposed
to be stateless in that it shouldn't remember that I clicked a button

before
the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load

event
hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need

to
check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save"

onClick="btnSave_Click"
/>

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9


Nov 19 '05 #3

P: n/a
Regarding state, the ViewState technology is designed specifically to store
the state of your controls, so that you don't have to persist and
re-populate them on every page refresh. So the contents of your textboxes,
the selection of your comboboxes, etc. should all carry through the postback
when ViewState is enabled.

Regarding the refresh behavior, it's somewhat browser-dependant. IE knows
that you last requested the current page using an HTTP-POST (since you
clicked the Save button and a postback occurred); and it also remembers the
contents of the POST. When you refresh, IE normally will warn you that a
refresh will cause the same form data to be resubmitted; my guess is that
you've disabled this warning in IE's advanced settings.

In short, the behavior you're seeing is entirely normal and is working
exactly as intended.
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh is actually calling my last onClick event. I thought that asp.net was supposed to be stateless in that it shouldn't remember that I clicked a button before the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load event hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need to check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save" onClick="btnSave_Click" />

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9

Nov 19 '05 #4

P: n/a
> I'm not sure I unserstand everything, but what it sounds like you're
saying
is that the page refresh is functioning correctly. Is that true? Is it true that the onclick event handler which was last initiated will again be
initiated on a page refresh? Maybe I'm wrong, but I was told by others that ONLY the Page_Load should be kicked off when I refresh the page, not the
Page_Load + the event handler.


It is behaving correctly. On the very first visit to the page, Page_Load
executes and hitting refresh will execute ONLY Page_Load. If you do a
postback event (e.g. click a button), then the browser does an HTTP-POST.
Refreshing that resulting page (under modern browsers like IE) will cause
the full header to be resubmited, and ASP.NET will follow the same execution
path; Page_Load first, and then your Button_Click event.

Nov 19 '05 #5

P: n/a
If you click off the page and go to a seperate website, and then come
back to the page via link or typing it in the url you will see that it
won't have the same data but the normal generic view it should have.
Without any saved form data.

Nov 19 '05 #6

P: n/a
PK9
Thank you for the in depth explanation. That helps a lot, I've created a
workaround based on the information you gave.

"MWells" wrote:
Regarding state, the ViewState technology is designed specifically to store
the state of your controls, so that you don't have to persist and
re-populate them on every page refresh. So the contents of your textboxes,
the selection of your comboboxes, etc. should all carry through the postback
when ViewState is enabled.

Regarding the refresh behavior, it's somewhat browser-dependant. IE knows
that you last requested the current page using an HTTP-POST (since you
clicked the Save button and a postback occurred); and it also remembers the
contents of the POST. When you refresh, IE normally will warn you that a
refresh will cause the same form data to be resubmitted; my guess is that
you've disabled this warning in IE's advanced settings.

In short, the behavior you're seeing is entirely normal and is working
exactly as intended.
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh

is
actually calling my last onClick event. I thought that asp.net was

supposed
to be stateless in that it shouldn't remember that I clicked a button

before
the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load

event
hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need

to
check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save"

onClick="btnSave_Click"
/>

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9


Nov 19 '05 #7

P: n/a
Dino Esposito wrote some code to show one way to trap for this:
http://www.dotmugs.ch/events/event.aspx?eid=17
--
Joe Fallon

"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh
is
actually calling my last onClick event. I thought that asp.net was
supposed
to be stateless in that it shouldn't remember that I clicked a button
before
the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load
event
hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need
to
check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save"
onClick="btnSave_Click"
/>

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9

Nov 19 '05 #8

P: n/a
PK9
Thanks for the link.

"Joe Fallon" wrote:
Dino Esposito wrote some code to show one way to trap for this:
http://www.dotmugs.ch/events/event.aspx?eid=17
--
Joe Fallon

"PK9" <PK*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I'm having an issue with the "Refresh" of an asp.net page. The refresh
is
actually calling my last onClick event. I thought that asp.net was
supposed
to be stateless in that it shouldn't remember that I clicked a button
before
the refresh. Here is what is going on:

1) Page Loads
2) User enters some values, clicks the "Save" button
3) The onClick event handler for the save button saves the data to the
database and the page is re-displayed with the new results.
*** Everything is fine up until point #4
4) I click the "Refresh" button on my browser (Internet Explorer v6.0).
5) As I step through the code, the execution goes through my Page_Load
event
hanlder and my btnSave_onClick event handler.

I don't think it should ever return to my onClick event handler when I
refresh the page. Is their some type of setting or configuration I need
to
check. At the page level, I have EnabledViewState = true.

Additional Information (if necessary):
Here is the declaration of my control & my event handler if this helps.
Button declaration in asp.net page:
<asp:Button ID="btnSave" Runat="server" Text="Save"
onClick="btnSave_Click"
/>

onClick event handler in code behind page
public void btnSave_Click(object sender, System.EventArgs e)
{
//......
}
--
PK9


Nov 19 '05 #9

P: n/a
Chad Devine wrote:
If you click off the page and go to a seperate website, and then come
back to the page via link or typing it in the url you will see that it
won't have the same data but the normal generic view it should have.
Without any saved form data.


That's because these operations use HTTP GET.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.