Web browser control detect form submitted? - c#

After a user submits a form, how do you detect that the form has been posted/submitted and the browser has navigated to the logged in page?

Handle the DocumentCompleted event and check e.Url.

Related

Why does the "Back" button on the browser trigger the last activated event?

I have 2 webpage, webpage A and webpage B.
What webpage A does
Webpage A have 2 event, Page_Load event and button_click event.
When Page_Load event is triggered it will check if user is logged in or not, if user is logged in it will redirect user to webpage B directly, if not nothing will happen.
When the button on webpage A is clicked, the user stats will become logged in and redirect to webpage B.
What webpage B does
Webpage B have Page_Load event only.
When Page_Load event is triggered it will check if the user is logged in or not, if the user is logged in it will stay at the webpage, and if it is not it will redirect back to webpage A.
The problem I am facing right now is, if I load webpage A in not logged in stats, click the button proceed to webpage B and click the browser's back button on the top left of the browser, it will proceed to webpage A and trigger the button_click event (which is the last triggered event on webpage A) instead of the Page_Load event which the user is in logged in stats but is not redirected to webpage B.
PS. Webpage A's Page_Load event is not triggered at all when user press the back button.
PSS. Both my event is written in C#(asp.net).
What is the cause of this and how do I fix this? Thanks.
UPDATE
I found out that this problem only occurs when my webpage A's button_click event occur once but doesn't redirect (try to login but login failed/denied). Then on the second click it worked, proceed to webpage B, right now if click back the fail condition will be shown and Page_Load event not triggered. I feel like this is something to do with cache or Ram? Is there anyway to let my webpage "forget" it failed once and goes back to webpage A as nothing happened before?

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

Redirect open link event to extendedwebbrowser tab

I've got a webbrowser in a c# form and when the user click on a link the page opens in the ie10 browser.
All I want is to intercept this event and open the new page in another webbrowser (extendendwebbrowser really).
The fact is that i don't want to know what the user click in the page, but i'd like to intercept all the requests "open new page" from my webbrowser and redirect them to my extendedwebbrowserform and create a new tab with that link.
Thanks for help.
There are at least 2 ways to do that:
Extend the WebBrowser control to intercept the NewWindow2 event, then cancel original request and use that url to open it in a new window. Similar code can be found here or in code project Extended .NET 2.0 WebBrowser Control.
Implement INewWindowManager, and use EvaluateNewWindow to do the same.

How to detect navigate out in WebBrowser control

On Load you load a Url.
How do you detect and fire an event when the user navigates away from a page? (example click on web page button/link)
When new navigation begins, i.e. Navigating.
Actually the same Navigating occurs when you type a url, click a link, etc.
Load occurs on the form, or user control, when it loads. WebBrowser control has no such event.

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