473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Page Refresh issue

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
9 7693
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
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
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
> 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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ppatel | last post by:
Problem I have a problem with web image button control click event. The click event does not get trigger until it has not been clicked once or page refresh occures(which is fine). When click...
4
by: Lenny Shprekher | last post by:
I am using regular server site ASP.NET button to execute function. Works fine, issue is that when I call page-refresh on IE after click I done it is calling same event again. Could anybody suggest...
0
by: Lenny Shprekher | last post by:
Could I use this property in subject to prevent button_click function called on page refresh? Seems working. Thanks, Leonid
0
by: Neel B via .NET 247 | last post by:
I have datagrid, i am using xml file to populate the grid, i am able to add a row delete a row in both xml file and datagrid fine, here are some issues i am facing now: 1. Sometimes datagrid is...
10
by: Fred Nelson | last post by:
Hi: I have a VB.NET web application and I need to find a way to cause a page refresh from within my application. Does anyone know how to force the browser to refresh the current page? ...
2
by: adam | last post by:
Hi ASP Expert, I encounter a page reload situation in ASP. It is I need a way to differentiate whether the current page - "Application_Result.asp" got reloaded itself when user click on the...
1
by: Ibrahim. | last post by:
Hi, I have a login page, the problem I'm facing is like this; 1. Login page with submit button (being default button); 2. When first time the page is submitted then submit code is called. ...
4
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. If an ASP.NET page postsback, for example, after a button is clicked, and then I refresh the page (ie, by pressing F5 key), why does the same event occur when I press F5 as it did when I...
11
by: gotonagle | last post by:
hi, can some help me in this regard i m entering some values in my databse from my asp page. for this i m using a submit button which submit the form to a new page that is 'insert.asp'. this page...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.