close current web form in asp.net - asp.net

How i can close current web form in web based application?
I have tried with following code:
mybutton.Attributes.Add("onclick","window.close()")
But its not working
Help me. Thank you.

You can use window.close() to close a pop-up window only. If you really need to close the window, use a pop-up instead. However review why the closing is important? You may consider a redirection (either server.transfer or response.redirect).
Update:
Looking at the discussion at this stage, we need to see the relevance of why wee need to close the window as desired. What is the business value that we are achieving?

You can use the following script to close the current window in Chrome and IE (I checked in IE8).
mybutton.Attributes.Add("onclick", "window.open('', '_self');window.close();");
but it still won't work in Firefox. See more info on this: How can I close a window with Javascript on Mozilla Firefox 3?
But because it is a workaround (as Kangkan said window.close() should be used only to close popup window created by window.open() ), it is not a reliable solution and can be broken if a new browser version is out.
Bottom line: there is no reliable, universal solution for your problem, there is no proper way to close a non-popup window from javascript. If you can rely on the fact that your site will be used only in IE, Chrome, etc. you can use a workaround/hack (see above - but don't forget, it can easily be broken in next browser release), otherwise you should consider a different approach of the problem, instead of closing the window.

Related

Open a URL in a certain browser tab/window

From within my Qt application, I would like to open URLs repeatedly in the same browser tab/window. (Kind of "refreshing" this tab programmatically)
Using
QDesktopServices::openUrl(QUrl("http://www.domain.tld"));
opens a new tab/window for every call. Is there a possibility to add a "target=" parameter somewhere?
What you are asking for is impossible to do in the way you imagine it. openUrl() uses the operating system to specify the program to open the argument as mentioned in its documentation.
There might be some workarounds, but none of them will work well, or work on all browsers. It's just that this kind of fine-grained control is likely to be impossible for you.
If you want control of a tab in a browser, you could find the window represented by that tab and close it right before opening the new one. This solution is kind of hacky.
Another hacky solution is to find the HWND of the edit box holding the URL, and to try changing its text using SendMessage(). This won't work on Chrome, however, as it does not use a separate control for the URL window. It might work on Firefox or IE.
The better solution is to make your own web browser you control using the Qt WebKit. It is pretty easy to render a page in it and change the url viewed. The QWebView is an easy to use implementation of the QtWebKit.
Maybe you will found this usefull:
You can open the webpage and the reload the active tab.
If you supply the name of the browser as an argument, it'll find and reload the current page
https://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line

How do I make a mobile-friendly popup on my website?

Is there a simple way to trigger a mobile OS's native pop-up/alert/etc. from some form of web code? I'm writing an ASP.NET mobile web page and I'd like to, for example, have the iPhone's UIAlertView appear.
EDIT: What I'm looking for is not the method with which to detect which mobile browser is accessing the site (I already know how to do that). If the code to trigger a pop-up that will look nice in an Android browser is different than the code to trigger a pop-up that will look nice in an iPhone browser, I can simply throw in a switch statement that redirects the user to the pop-up that corresponds with their browser. I'm trying to find the html/javascript/asp.net code which will create a mobile-friendly pop-up, either in general or for the various popular mobile web browsers specifically.
Don't know whether there is any pre-built functionality in .NET that can achieve this, but you can surely write one yourself.
You can write a method, that returns the code for your popup, based on the user OS (simple switch statement should do).
EDIT after taking a short nap:
I believe you should reconsider using popups. They are quite annoying even on desktop browsers and many people block them automatically. Probably every blog about accessibility will tell you, that you should keep mobile version of your website as simple as possible because of various compatibility issues that you can run into.
Instead, try to think about some interesting way to incorporate messages for users in a different and appealing way, that won't disturb anybody.
What I do is use a div popup (that floats ontop of the page) and eighter make a big close button or set at timeout to remove it.
jquery mobile is a good place to start.

Disable Focus to Browser

Can any one tell how to disable focus to a browser.
Hi i am currently working in .net application and i need to disable the tab focus to browser objects such as toolbars,address bar, since the user will not be using these components often
Thank you
Please don't do this, it breaks what the user expects a webpage to do. Messing with the fundamental behavior breaks several things:
My tab button and where I expect it to go
Screen readers for the disabled
Trust in your application
In some cases, you need to ask why? before asking how?, this is one of those. Anything that behaves differently from the other 99.9999% of the web is broken in the eyes of your user.
Well, I agree with Nick Craver. If you have to disable due to some crap requirements, then try opening a new window without toolbar, editable address bar etc and load the page inside the newly opened window.

I don't want to display back and forward button in my browser. Is there any solution apart from popup trick?

customers does not want to allow user to use back or forward button. Just a clean page without commandbar and toolbar, same for FF an IE.
Disabling them is not an option as now.
You cannot change that kind of thing in a existing window -- the only way you can make those disappear is by opening a popup, specifying they should not appear in that popup when it's being opened.
Still, note that you should not try to disable those buttons nor have them disappear : your application should work fine with them, handle their actions -- after all, it's one of the few things users have understood in browsers...
And as a user, this is disturbing and annoying :
I don't like popup windows -- and I'm not the only one who doesn't
I don't like when a website tryies to take control over my browser
It will not always work anyway.
And, as a sidenote : even if the back/forward buttons are not displayed, users can still use Ctrl+left/right or some kind of equivalent !
I know this is not easy, but a part of your work as a web-developper is to explain your clients how Internet and web-applications work... not the same way as desktop applications !
If you can force your users into IE (can't believe I'm suggesting use of IE!) you can do this trick. Try running this from the command line
"C:\Program Files\Internet Explorer\iexplore.exe" -k
This will force IE into kiosk (or full screen mode), similar to pressing F11 when in a usual browser session.
PS. I agree with the other answers suggesting this should be discouraged but there are instances (such as when the end user really can't be trusted) that this is a good solution.
No, there's no other way.
However, this is extremely annoying behavior and should be greatly discouraged. This isn't a code issue to solve...this is behavior that shouldn't be implemented at all.
My opinion here, you have a client problem not a code problem. Whatever standard is the expectation, and the user has the expectation of having their back/forward buttons, break that and you break their experience.
Ever see a Windows application that removes the taskbar? That's the equivalent...
I don't think there is a reasonable way to disable the behavior. You may get rid of the buttons in various ways, but the behavior is still there (through keyboard commands, popup menus and so on).
The only reasonable way is to make your web application follow web semantics, and make the client realize this.
many web based ERP (for example) does not tolerate people using navigation buttons. BUT these web applications handle the fact people use these buttons and do not crash. That's what you should do. If each time people use the back button, they get an error message, they will quickly stop using it.
The solution that used to work in IE was adding a startup script with one line:
location.forward();

PopUp window in IE 6 SSL

I have a weird issue. I am opening a popup window in IE6 with SSL enabled on the server.
When the following executes it seems to lock the browser up. I know this is vague. This is the JScript that appears to be the problem. Gotta love your IE6!
function PopoffWindow(url) {
var features = "height=400,width=550,top=60,left=100,"
+ "toolbar=no,location=no,menubar=no,status=no,"
+ "scrollbars=yes,resizable=yes";
var win = window.open(url, "DSRocks", features);
win.focus();
return win;
}
This is not a problem in IE7 or Firefox. And the problem seems to be isolated to this server (with SSL). Anyone have any insight on this?
Thanks,
Nick
Is it possible that the window.open call does not return quickly enough to allow you to perform a .focus() on it, in the next line?
What happens if you throw an alert() between those two lines?
have you tried assign the window a name? IE6 sometimes does funny things when you open an unnamed window. just add a "windowName", before the url
With a problem like this, it is usually best to get back to basics. A few things to check:
How are you testing IE6? Are you using the Microsoft Internet Explorer Application Compatibility VPC Image or some workstation install where you've managed to get IE6 and IE7 working on the same PC? Having both IE6 and IE7 on the same PC may appear to work, but lead to issues like you are seeing. Even if you are using an existing VPC Image, you may want to download (or extract from an existing download) a fresh copy and see if it happens on that copy of IE6.
Have you cleared the Temporary Internet Files, Cookies and History of the IE6 install? I know it sounds obvious and stupid, but perhaps a resource that is being loaded in the PopUp window is corrupt in cache, causing the problem.
Have you disabled every Add-on in IE6?
I think the first thing to determine is whether the problem is with every copy of IE6, or just your copy of IE6 (covered by the first bullet point).
Grant,
Thanks. But the problem is with all IE6 instances that are viewing the hosted site. I will try to add an alert before the focus() to see if this is the issue. As for the windowname.. that is the second parameter I am passing, "DSRocks".
The problem was with a JSON webservice call. Please see this link for details:
http://codeclimber.net.nz/archive/2006/12/22/How-to-enable-an-ASP.NET-WebService-to-listen-to-HTTP.aspx

Resources