Does anyone know how to block browser back button? [duplicate] - c#

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Disable browser's back button
i have one button on page
on that button click event page will redirect on the next page
now i click on the browser back button
but i want to restrict browser back button for some security purpose
does any one know how to block browser back button so that page can not redirect to previous page?

Do not disable expected browser behaviour and you can handle the possiblity at your end, but if you really want to do so,
there is one work around here...
Just put this javascript on the html section of aspx page above head section.
This causes every back to return with
a forward.
<script type = "text/javascript" >
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>

Open the webpage in a popup window rather than normal window. So, that you can restrict the popup window from displaying buttons, menus, status and other features.

Related

Confirming asp c# action on page load

I've been searching for an answer to this but haven't found what I'm looking for yet.
When I load into the page there is a check run one the server side. Depending on the output of this (bool), I wish to display a "yes no" confirm box to execute another piece of server side code.
I have found ways to do this easily enough on a button click but I'm trying to avoid adding a hidden button and simulating a click.
MessageBox.Show isn't an option in this case as I get the following error:
Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation
Is there any way to achieve this without simulating a button click?
Cheers,
Spitfire2k6
In web app (including the one created with ASP.NET) you can use Javascript confirmation dialog box: window.confirm("Request to Confirm Text");, and process User's response like in the following sample code snippet:
var _response = confirm("Please Confirm");
if (_response == true) {//Do Action1}
else {//Do Action1}
Pertinent to your case, you can use for e.g. page <body onload> event. Hope this may help.
I realised I was going about this all wrong.
The check is now done on page load, depending on the result I'm showing an asp panel with 2 asp buttons as a confirm box.
Thanks for all guidance.
Cheers,
Spitfire2k6

WebBrowser - Click Dialogue Button

I am using the .NET WebBrowser control to automate some web tasks, however now and again the website I am visiting will produce a dialogue box with a YES/NO button that I need to press.
The dialogue is popped up using a Javascript modal window. I need the WebBrowser to detect a Javascript modal popup, get the source of the popup to define the response to give, and then click one of the buttons.
Can this be achieved?
I've encountered a similar situation
But in my case it is just a simple confirm dialog so I simply skip it by removing the confirm javascript command from the html element.
Here's the javascript code that invoke the dialog
confirm('Comfirm to kill');
here's the full html tag of the button that invoke the dialog
<a id="inputID" onclick="return confirm('Comfirm to kill.');" href="javascript:__doPostBack('ctl00$ContentMainContent$gvOnlineUser$ctl02$btnAction','')">
And here I remove the js to call the function
HtmlElement elementButton = doc.GetElementById("inputID");
elementButton.SetAttribute("onclick", "return true;");
elementButton.InvokeMember("Click");
That should skip the confirmation dialog part
I'm not sure it would work in your case though
Hope this help anyway

Deciding whether javascript is disabled/enabled and execute a server side code [duplicate]

This question already has answers here:
redirect to another page if javascript is disabled [duplicate]
(5 answers)
Closed 2 years ago.
I've an aspx page which loads several images after detecting client's screen size. Here is how I do this:
In jquery code, I first detect user screen size, then depending on the size, I do some calculations to decide the number of images to be fetched from database. Then with the use of jquery ajax, I call up a web service which returns json response. Code picks up json and creates page.
Now, if user has disabled javascript, this approach doesn't work. Now I have to create page using c# code on code behind. The problem is, I can't detect if javascript is disabled from code behind (I think this is not possible). I do not want to display a button at the top says something "Javascript is disable in your browser. Please click here to display this page". I can put this button in noscript tags. But I do not want user have to click a button before seeing images on page.
What I want, if javascript is disabled, system should detect it and immediately run a function from code behind. (IN this case page size would be fixed and won't vary according to user screen) I can not use a hidden field or cookie to detect it since they both will need a postback before detecting javascript is diabled. (We know that js code can't run before any page life-cycle event).
Well I don't have much hope that my problem could be resolved, but still I want to give it a try. May be someone already have a solution. It would be extremely helpful if you could give your views or suggestion to change/update logic.
Any help would be greatly appreciated.
Thanks and Regards
Praveen
1.) Use JavaScript to set a cookie, and then test for that cookie using server-side scripting upon subsequent page views; deliver content appropriately.
How to detect if JavaScript is disabled?
2.) You can use <noscript> tag.
The <noscript> tag: can be used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.
<noscript>
....
</noscript>
3.) Detect if JavaScript is enabled in ASPX
protected void Page_Load(object sender, EventArgs e)
{
if (Session["JSChecked"] == null)
//JSChecked -indicates if it tried to run the javascript version
{
// prevent infinite loop
Session["JSChecked"] = "Checked";
string path = Request.Url + "?JScript=1";
Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect",
"window.location.href='" + path + "';", true);
}
if (Request.QueryString["JScript"] == null)
Response.Write("JavaScript is not enabled.");
else
Response.Write("JavaScript is enabled.");
}
Make default version without javascript and redirect to javascript version if javascript enabled. How to redirect if javaScript is disabled?

Fire Event after Page Close or Redirected to other page

I have some problems with ASP.NET page cycle. I want to fire event when page is going to be closed or redirected to other page. I try to use Page_Unload() but it is going to be fire when page display and in any button click event it is firing Page_Unload(). I want only to fire event when page is going to be redirected or close. Then I have tried to use the Javascript function window.onunload(). Again, same problem: it is firing when the first page displays. Is there any way to solve this?
Look into Jquery's .beforeunload property. Here is an example:
$(window).bind('beforeunload', function(){ return 'Click OK to exit'; });
Please note, beforeunload canot prevent a page from unloading or redirect it to another page for obvious reasons; it would be too easy to abuse. Also if you just want to run a function before unloading, try the following:
$(window).unload(function(){ alert('Bye.'); });
Finally, don't forget to referrence jQuery in your head tag by using:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
The above gets you the latest version from the internet and saves you the trouble to download it, and of course you can do so optionally, but I am just trying to get your thing to work asap.
Oh, I also found an example for you. Click here to see a page that calls a function before it closes. Hope this helps bud.

Child webpages help

Using C#, ASP.Net
In my webpage i have the link for the another web page, if i click the link that should display a another page inside the main page like child page.
Another webpage should display like a popup window in my webpage. And also size of the another webpage should be small. How to do this.
Need Help.
For displaying one web page within another look at using frames (or an inline frame - iFrame)
The second part of your question I think is asking to be able to display the link in a separate window. To do this, use the target="blank" attribute in the anchor tag. to set the size of the child window you will need to use javascript:
<script type="text/javascript">
function showPopup(url) {
newwindow=window.open(url,'name','height=190,width=520,top=200,left=300,resizable');
if (window.focus) {newwindow.focus()}
}
</script>
So just call the showPopup method from your anchor click event
link text
Ideally you would move the javascript so that it is no longer inline, but this should work.
For the first part you need a master page
For the second part you might need a modal popup or it's jQuery equivalent
However, I don't understand what you mean with
And also size of the another webpage should be small. How to do this.
Another webpage should display like a
popup window in my webpage. And also
size of the another webpage should be
small. How to do this.
Did you mean a jQuery Modal Window?

Categories

Resources