closing message keeps showing when close the browser programatically - c#

I am working with just IE
I want to implement a button, when the user clicks it, the browser will close
I did this:
ClientScript.RegisterStartupScript(typeof(Page), "closePage", "<script type='text/JavaScript'>window.close();</script>");
the browser really close, but every time I click that button, I got a message from IE states that the web page will be close, with two options yes, and no.
is there any way to avoid that button?

Related

How to close aspx page programmatically through master page

I'm trying to close the browser tab when user clicks on logout button or session expires but i am not able to close the tab
I have tried using the below solution but its not working.
ScriptManager.RegisterStartupScript(this, this.GetType(), "Close_Window", "window.close();", true);
When using the above code I'm getting console warning in the browser.
"Scripts may close only the windows that were opened by it."
Any help will be appreciated.
I would recommend that the logout action and expiring session will redirect you to a different page of your preference (e.g. Home page, Login Page, etc). Which you will normally encounter from other websites like social media sites.
Using window.close for certain browsers are considered risky just like how you received the warning message, because the window/tab was not opened (initiated) by the script themselves.
There are probably some workarounds that you can find, but that will still depend per browser, and the hack might differ among them. So I would not suggest this. But still you can find some details about this here in a SO question.

WebElement.click() causes page refresh

I have a <button> element. I call the click() function on this element using chrome webdriver.
appDone = driver.FindElement(By.Id(Constants.APP_DONE));
appDone.Click();
A strange thing happens in chrome, the page actually get reloaded. A pop up comes
"Are you sure you want to leave the page? You have unsaved data" Leave/Stay (buttons)
But same click event works fine in other browsers (Edge, IE, Edge). I opened the console in Chrome before clicking the button and placed debugger. Then executed the button click, the console window goes out a new console window comes up.
Anyone knows why this happens?
Things I have tried so far:
executed the button click using IJavaScriptExecutor
There is an beforeunload event in page, so when I pass onbeforeunload = null, I don't see the page refresh pop up anymore, but page still refreshes.
Tried to add type = button in the button, still no luck.
This screen works fine when run manually without Automation.
I have few logs recorded in server side, so when a page refresh happens, those logs are actually getting deleted, which should not happen.

How to get fresh page after pressing F5 or refresh icon in browser in MVC5 when errors occured?

In my login page,when credentials are wrong ,it gives error.but when i pressed F5 or refresh button in browser,it shows same error page not giving refreshed page.
Hitting F5 causes the form to repost. You cannot by-pass this feature since it's build in every browser.
You can click on the address bar and press enter. This way you will request a new page without form data.
If you want your user to been able to clear the validation errors then provide them with a 'x' button that clear these errors.

Simulating a button click within ascx page

I need to simulate a button click on my ascx page. The user firstly clicks on a button on the service home page which links to a certain service and a new window opens for that related service. If they are not logged in it directs them to the login page. A querystring is sent with it to keep note of what service they had originally clicked. When the user then logs in they are redirected back to the services page and the querystring of what they clicked on before is sent also.
I have up to this point working fine. The problem is that when I'm redirected back to the online services page I need to simulate an onclick event which will open the new window. I cant click on an the onclick method for the button as there is none, everything is done dynamically. Any ideas?
I would have thought the easiest way to achieve what it sounds like you're trying to do is in the code behind for your Online Services Page check to see whether the query string contains the url for the service they clicked on before you sent them to the login page, if it does then add some javascript to run on start up which launches the pop-up (using the ClientScriptManager.RegisterStartupScript method: http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx).
If you absolutely have to fire the click event you can also do that from your javascript by finding the button you want to click by it's ClientId (using getElementById) and then calling the javascript click() method on it. Here is an example: http://www.w3schools.com/jsref/met_html_click.asp

webBrowser popup window loses session

I am using WebBrowser control of .NET to login into a website. When i click on a button that popups a new window the popup window asks me to login again. However i am not asked to login again if i open the webpage in internet explorer. Is there any way to make the WebBrowser control store session so that i do not have to login again on the popup window.
To maintain the session state you can use the NewWindow2 event to open the new page in another form in the application; the event is triggered by the WebBrowser control.
Make sure that before clicking the button you already made Login.
In both cases, I think the solution which I am going to give will work for you.
For this purpose, I think you place login fields in panel and on page_load check either session empty or not if not then visible it false if yes then visible it true.

Categories

Resources