GridView's RowCommand - detecting a page refresh and not reexecuting
I have a GridView which has a RowCommand event that opens a modalpopupextender on click. A slight problem is that if a user opens and closes a modalpopup, then refreshes the page, the popup pops up again - presumably because the refresh is causing a refire of the RowCommand event.
How can I detect this and avoid opening the window a开发者_开发知识库gain?
EDIT: I'm using the AJAX Toolkit, and the modal pop up is clientside, but is called from the RowCommand event
If the reload again triggers the rowcommand event, it appears, you are using get parameters? In general, you will have to track the responses from/to the client and decide for every response individually, how to handle it. One way to archieve this:
Provide a "page-delivery-counter" within every delivered page. It is maintained on the server side and increased for every page response. (for now, let things like multithreading and possible restarting of worker process aside here - this answer is only to demonstrate the general scheme. But consider managing the counter on a per user base, ie. store it in the session of the user, if any.)
Register the counter in a collection on the server and also send it in a hidden variable to the client. If a postback comes in, read its counter value and check, if it belongs to an response already used before. This would mark the situation you described (the user hitting reload).
Your problem in refreshing or(F5).So you need to detect if it 's refresh or just normal post back..
Try this:
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
This will capture the refresh,allowing you to show an message about this.
Other links that will be good for you:
-asp.net problem with F5 after postback, cuz it does what it should
-C# validate repeat last PostBack when hit Refresh (F5)
-Detecting Refresh or Post back in ASP.NET
精彩评论