Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello experts,

I am working on c# asp.net web page development.
I have to disallow the site from reopening in other tabs or other browser windows.
That I am able to handle generating unique PageId. When the user opens the same site in another tab or new browser window, a new page id is generated,
I check it against the current page id and redirect it to the error page.
But when I refresh the page, I also get the new PageId and not the existing one and so it gets redirected to the error page.
I searched on internet for solutions but none of those solutions are working for me. How can I detect a refresh??
Can you please guide me on how to handle this??

Thanks
RaesaRk
Posted

1 solution

Your best bet is to look at the page events

http://msdn.microsoft.com/en-us/library/aa479007.aspx[^]

You can add your custom code in these events to see if your PageID matches and prevent the page from loading.

1. Look at the page load, you can do an if test to see if the page is post back
2. Look at the unload event

If you dont understand the post back read this article for a basic explaination

Detecting Refresh or Postback in ASP.NET[^]

Make sure the you have you are calling you function onPostBack like in the example or you wont generate the new id on refreshing the page.

<form id="form1" runat="server" onsubmit="onPostBack()">
 
Share this answer
 
v4
Comments
raesark 14-Nov-12 10:19am    
Hello,

Thanks for your reply.
But when I refresh, I get a new Id and the code redirects it to the error page.
I am not able to detect the refresh action.

RaesaRK
[no name] 14-Nov-12 10:49am    
If you read the article that I added to the bottom of the solution it might explain why your PageID keeps changing and it gives you ideas on how to manage your refresh problem
raesark 15-Nov-12 9:24am    
Hello Mathlab,

I read the article that you had posted at the bottom of the solution.
I tried implementing on a test work space and it works fine. But when I implement the same javascript in my code, it doesn't work. When I hit the button or any other control, it does not do any action. I tried debugging the script and it exits at this location:

--------------
if (continueSubmit) {
for (i = 0, l = this._onSubmitStatements.length; i < l; i++) {
if (!this._onSubmitStatements[i]()) {
continueSubmit = false;
break;
}
}
}

if (!continueSubmit) {
if (evt) {
evt.preventDefault();
}
return;
}
--------------

Could this be some settings issue? I had given all the settings that are needed in the web config file.
Can you throw some light as to where the problem is?

Thanks
RaesaRK
[no name] 15-Nov-12 9:58am    
I assume your continue sublit is where you check if the page ID has changed. Did you put in the client script to create the new id on refresh?
[no name] 15-Nov-12 9:58am    
You have to add the script tag to the .aspx page for the .js file in the example and in the form tag you have to add the onsubmit behavior and make it equal to the onPostback function in the client script.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900