How to delete Webbrowser form data? - c#

I'm using a
system.windows.forms.webbrowser
to login into facebook. When the next user logs in I want the login form to be totally blank and not have the name of the previous user in there. How can I do that?

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk.
When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again.
Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

You could use JavaScript to do this (Not pretty but it does it in 1-2 lines of code).
The markup below is not correct, it is an example.
WebBrowrower1.Navigate("javascript: void Document(somegetelementbyID/Tagname('').value = '')");

Related

JS Redirect to page w/ postback or cache

I have a webforms site that has 2 menus.
On a page you click a button, has some c# events fired by a webservice (ajax) then redirects you to another page with history.go(-1). The only problem is that in the webservice I create a sesion that makes the menus switch, the default one hides and the other one shows. The menu switch in done in the Page_Load of the Master page.
My problem is that with history.go(-1) you get to the previous page, but the old menu is present instead of the new one. How can I fix it?
the problem is that the browser is not actually loading the previous page it is using the cached page. is there a reason you can not have both menus hidden and then decide what one to show client side? this way you can let the JS .ready take care of what menu to show and then you should get the desired results when using the history.go(-1).
This artical speakes to setting cookie from the server then checking in on the client.
you could use something like this and then check the cookie to determine if the page was loaded from cache and then force a postback.
location.reload()
My fix was to add in a session the previos link, and when I need a redirect w/ cache I redirect to another aspx page, that redirects depengind on the url params where I need it to go... it was the simpler method I could thing of...

Webbrowser and IE acts differently?

I'm in a trouble trying to fix some problem.. I have a program with Webbrowser control inside it.
It automates crawling process from some website. The problem is that I cannot fix webbrowser after recent website changes.
They have changed page navigation on website. And when I do actions MANUALLY in webbrowser (in my app) it doesn't go to the next/previous page on website. It does nothing... Whereas it works properly in IE 7/8/9 (only scripting errors thrown this time).
So does it mean that Webbrowser is not fully similar to IE??
I'm sorry for not showing source codes here, I think it wouldn't help here. Which way should I go to troubleshoot it? Why page navigation is not working in Webbrowser control?
I tried to simply put Webbrowser on a Window Form in new project and tried to navigate page 2/3/../10 in the website catalog, but it simply changes page number and doesn't navigate to it...
EDIT: Website doesn't work propely even if I do actions manually in webbrowser using mouse clicks.. but works in IE.
EDIT2: I might be not clear in my question. The problem is that I cannot use website even Manually with mouseclicks via my Webbrowser control in app. It changes page number after I click on it, but it doesn't navigate to that page. It stays silent. I'm sure that AllowNavigation property is true. It worked just yesterday and stopped after website changes today... Please tell me which way should I go to troubleshoot it.. I thought that Webbrowser control acts the same way as Internet Explorer.. Any help from you highly appreciated! Thanks
EDIT3: Strange thing... i just loaded Extended Webbrowser and navigated to that website. Page navigation panel doesn't work there also.. Is it a bug on their side or some type of guard from crawlers? What do you think?
(http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx)
I'm sure this isn't the answer your want but using the webbrowser control to scrape websites is very painful to maintain.
Instead use the HttpWebRequest and HttpWebRepsonse objects to recreate the calls to the webserver.
You can use Fiddler (http://www.fiddler2.com/fiddler2) and your browser to record your web sessions and recreate them in code.
You can setup your webbrowser control to disable a number of features including navigation.
I.e. to disable nav in the C# WebBrowser control:
webBrowser1.AllowNavigation = false;
I'd double check that you're not doing anything like this.
I had the same issue with a certain web site that recently changed its format. It has to do with the version of IE used by the control.
Simply force the IE version used to the latest (in my case 9). Setting the appropriate registry item to 9999 for my application worked; see: Webbrowser control behaving different than IE

Browser's back button disables randomly in ASP.NET application

On my two-page web application, users progressively enter info and make selections on page one. When done, they click a 'Generate' button that navigates to page two. Users print that page and hit the browser's Back arrow to return to page one with selections intact.
After a few generated pages (2 or 3), clicking Back just disables the icon without going back. They have to manually revisit page one, reentering their info and selections.
I found that the down arrow to the right of to the Back / Forward arrows (IE8) that shows the immediate history generally includes all 'previous' pages. But when the back button is about to disable on click, the history only shows the current site.
What events, scripts, headers, etc. clear the history for the current site? It occurs in IE7 and IE8 on WinXP and Win7. In FireFox, the button did not disable, but it did not do anything either. Users report it as a recent and I have been making changes to the application, but it only affects the HTML on page two (not scripts, though). It's probably a code issue if it's recent, but I'm not sure what to look for when double checking my recent changes.
Which version of IE?
Internally, IE maintains a limited amount of data in the travellog (aka back/forward stack). ASP.NET pages with huge postback forms often blow this limit, wiping the history stack.
In IE6 and IE7, if there is a form input field with a value longer than 523,659 characters, when you navigate away from the page, IE may clear the current session's travellog (similar to history), disabling the back and forward buttons.
I believe the overall Travellog size limit was upped somewhat in IE8, but it's not more than a few megabytes.
As a general rule, if you want your users to navigate back and forth between pages, I would give them links on the page that do the job (without using javascript:back()) instead of using the browser's navigation.
What's happening, most likely, is that the postbacks of a single page are sometimes considered pages, sometimes not. If a user action loads a page that has the same URI and query string, most browsers consider that "the same page" even though EVERYTHING may have changed. This is usually due to heavy use of MultiViews with the information about the current view kept in ViewState or Session; navigating within that page doesn't change the URI being navigated to, so the browser doesn't log each new load as unique.
If you really need proper back-and-forth functionality, you will need to make sure that every link will result in the browser being told to navigate to a different URI than the current page. You can do this by adding a query string element that will be present in every link to a different page or view, that will auto-increment with each click the user takes. This gives the browser a different URI every time. You only use the existing QueryString element to create the new one on your links' URIs. This can get cumbersome, and the easier solution is simply to provide in-page navigation and tell your users not to hit "Back" any more.

how/where to store the page numbers when navigating to other page / portal

I'm using an usercontrol (*.ascx) in a CMS system C#.NET
I've got a Gridview which displays address. You hav a link on the line items and you can click on the items (link) which navigates to other page with querystring info and displays the detail information. When the user clicks on cancel/back it returns the the overview page. Both are separate programs.
When the user clicks on Next, Next, Next e.g. page 7 is displayed. So clicking on an "adres link" on Page 7 will open a new page and when the user comes back it should display page 7 back again.
I was keeping the page numbers in a session. so when the user comes back it reads the pagenumber from the session. This works fine. But the issue is this module is used other placess too, and also in other portals (which uses the same module)
So when have clicked next next etc and you are on page 7 and then you open another portal or other Porgram which have the same module, it displays page 7. Because it reads the Session variable and sometiems it gives a dump because page 7 doesn't exist, because no much records.
Viewstate fix this issue, but everytime after clicking the adres item and coming back it displays page 1, which is not what I want.
As I said, I use the same module in other pages and other portals (same program with different settings CMS -system)... So where and how do I need to store the pagenumbers so it doesn't have conflict with other pages and other portals?
ViewState["page"] = 7 -> starts on page 1 always when you come back
Session["page"] = 7 -> page number is shared....
Why don't you keep a Structure or Dictionary instead of simple int in the session. In this you can store Page as well as the Module.
I believe you need to think about instantiation. It seems that you need to isolate each instance of your CMS so each one will share its own set of server variables, includinig session ones.
Well, it's true you're using some ASCX control, but you can have some "application identifier" so any of control instances can have their own set of values.
Anyway, storing long objects in session is a bad practice, since other modes than "in process" will serialize objects and deserialize them whenever you access to session's state.
Maybe you need some kind of custom session management in order to optimize performance and memory usage so your components will be rightly isolated and they will remain performant.

How to display EULA in WP7 application?

As stated by Microsoft, it's not possible to programatically navigate from the main page. I have a EULA page that I need to show if the user is using the app for the first time. My plan was to determine on the main page if the app has been used before. If not, I had planned to navigate to the EULA page, but this is not possible. How can I get around this navigation limitation?
The issue with a dedicated EULA page that is automatically pushed on the back stack is that the application won't quit when the user presses the Back key when in the EULA page.
You should instead use a Popup control that you show and hide when appropriate.
See Peter Torr's post on how to exit an application for more details and background.
It should be possible to navigate from the main page easily using:
if (!eulaAgreed)
NavigationService.Navigate(new Uri("/EULAPage.xaml", UriKind.Relative));
Probably best to put this code in OnNavigatedTo of your main page or even later in the page cycle using Dispatcher.BeginInvoke(...). Putting it before that (i.e. in the constructor or Loaded) may not work.
What do you think happens to the Navigation stack?
Would the users be able to access the EULA page again? maybe by clicking back from the MainPage ?

Categories