WebBrowser.url not working some times in winform - c#

I set url value of a WebBrowser object on an event. Sometimes setting up of this value is not getting reflected in webBrowser.
The code I used is
webBrowser.Url= new Uri("www.google.com")
I also tried webBrowser.Navigate() but same behavior. Any ideas why it could be happening and what to do to overcome this?

Although very old question, for people visiting this, please check AllowNavigation property set on the WebBrowser instance.
As per MSDN documentation -
This property does not prevent you from loading an initial page by
setting the Url, DocumentText or DocumentStream property, but will
prevent all subsequent navigation.
You can find more details here.

Related

Validation of viewstate MAC failed with server.transfer

I've done some googling on this and i know a question similar to this has been asked several times, but so far I'm not having any luck.
I've got the home page on our site also set up to be the 404/410 error page. When I do a server.transfer to this page the search form on the page no longer works. Response.redirect to this page and it works fine.
So in my code the page doing the server transfer has
Server.Transfer("/default.aspx?status=410", false);
When i then use the search form on default.aspx after getting there from the transfer, i get the error in the title.
I also see that the action value on the form has a value, whereas normally it should be blank. I saw another post suggesting setting this value manually in my content page, but I would have to hardcode the ID for the form and I'm not sure if that would cause issues on other pages since this form is used by all the pages on the site since this master page is the main master page for the whole site. Plus even when i did hard code the ID and then used Page.Master.Findcontrol to get the form and set Action = "" it still had a value set for action instead of an empty string.
I had thought as long as I didn't use Server.Transfer("", true) I shouldn't get this error. And i do have a machineKey entry in my web.config
Anyone have any suggestions on how to resolve this?
Thanks
Server.Transfer()
and Response.Redirect()
both are performing same functionality like help to navigate user from one page to another, but internal process happening inside system little bit different. To get more idea about that please visit
http://www.dotnet-tricks.com/Tutorial/csharp/c4SE281212-Difference-between-Response.Redirect-and-Server.Transfer.html
I think i found a solution, although I'd appreciate some feedback to explain something.
On the page that's being transferred to (default.aspx) I tried using Form.Action = "" and when i loaded the page that resulted in the action being something like action="/../../../default.aspx"
Just now i tried it again but I used Form.Action = "/", which did set the action to "/" and that seems to work.
So i guess my question is why did trying to set the action to "" result in that relative url?
And is this the correct way to handle this problem?
Thanks

Page.Form.DefaultButton doesn't work in a page with no input

It is me or Page.Form.DefaultButton doesn't seem to work in a page with no input ? I tried looking for this information but found nothing. Cause right now I am on a page where I set the default button and this doesn't work at all.
I seem to recall this is a known issue.
You can also set a DefaultButton on an <asp:Panel> - is it practical for you to do this instead?
Actually thinking about it further I think if you add a hidden input on the page it would also fix your issue.
Try to set the default button to the specific panel or content.
Try that an let me know....

Click Gmail Refresh button

I am writing a simple personal app that has a browser control and I want it to automatically "Refresh" gmail to check it more often than it does by default. There are monkey scripts that do this but I'm trying to add my personal style to it.
Anyhow, I've looked around and found everything but what I can do in csharp using the browser control.
I found this:
// Link the ID from the web form to the Button var
theButton = webBrowser_Gmail.Document.GetElementById("Refresh");
// Now do the actual click.
theButton.InvokeMember("click");
But it comes back with null in 'theButton' so it doesn't invoke anything.
Anyone have any suggestions?
It's been awhile since I've used JavaScript, but given the other answers and comments that there is no real ID associated with the element, could you do something like the following:
Search all Div's with an attribute of Role == 'Button' and an InnerHtml == 'Refresh'.
Once the correct InnerHtml is found, get the Element.
Invoke the click on the found Element.
Again, this may be blowing smoke, but thought I'd throw it out there.
edit: Just realized you are doing this with C# and a browser control; however, the concept would still be the same.
The best suggestion I could give you at this point involves an existing API that is used for .NET web browser based automation:
http://watin.org/
Since the div tag with the desired button really only seems to identify itself with the class name, you could use the Find.BySelector(“”) code included with the most recent version of watin.

WPF WebBrowser Issues

I am using the WebBrowser in WPF like this:
<WebBrowser
Name="SSSBrowser"
Margin="8,4,8,8"
Grid.Row="1"
dp:WebBrowserUtility.BindableSource="{Binding WebAddress}"/>
And in C# I am loading it simply, for now, like this:
private string _webAddress;
public string WebAddress
{
get { return "http://www.somewebsite.com/updates/message/message.htm"; }
set { _webAddress = value; }
}
What I would like to do is prevent it from displaying an error if they cannot reach the webpage, for whatever reason.
How do I keep tell if the website returned an error in code and disable the WebBrowser so that it doesn't give an error on screen to user?
Any help would be greatly appreciated!
Not sure via WPF, but if you use HttpWebRequest and HttpWebResponse to programatically try to fetch your url first, the response will give you the http StatusCode, i.e. 200, 404 etc. Might be useful if you want to check for a 200 first and disable the browser preemptively. Not exactly the answer to your question, but a possibility.
If I'm right Source property is not bindable because it's not a dependency property.
Check out this post:
databind the Source property of the WebBrowser in WPF
Herber
There doesn't seem to be an ErrorOpeningURL event for the WPF WebBrowser object, so, judging by previous experience, you could wire up to the Navigated event and check whether the URI is the IE error page (res://Error.html.. IIRC) or dig into the NavigationEventArgs for the WebResponse and check the headers.
To suppress the error, hide the WebBrowser component, perhaps by covering with a polite message - your user will want to know that the operation did not succeed, but doesn't have to see the navigation FAIL.
You could try using the NavigationService from System.Windows.Controls.Frame as indicated in this MSDN forum post. The WebResponse will always be null for the WebBrowser control in WPF (as described in the post).

MultiViewControl issues

I'm presently in the process of reworking a MultiViewControl based wizard process for our web application. I am having an rough time trying to make sense of the order that events are happening (Page_Load, Init, prerender, etc). Does anyone out there on the interwebs have details on dealing with one of these controls? Please don't just say 'google' it. I've done that and have yet to find a good, comprehensive site yet.
Admittedly, I haven't really elaborated on the problems I'm having with this control, so I'll try to do that:
Primary problem is the initialization of UserControls that live in different Views. In the existing codebase, the programmer was using a combination of multiviewcontrol.ActiveViewIndex = WHATEVER and Response.Redirect("PageWithMultiView.aspx?nextstep") and it made it all very convoluted. My task is to attempt to remove the Response.Redirect calls and use only the setting of the ActiveViewIndex. Is this even possible? Also, there are some cases where I need to initialize a control in a particular view only on the initial load and not on subsequent postbacks. I can use something like the IsPostBack flag but this is only ever set to false on the initial load. Subsequent reloads IsPostBack == true. I basically want to have IsPostBack set to false for the initial load of each View. Can this be done without doing a Response.Redirect to itself?
Hopefully this will make some sense to someone out there.
Thanks.
Greg.
I am having an rough time trying to
make sense of the order that events
are happening (Page_Load, Init,
prerender, etc).
Here you have all details about ASP.NET page lifecycle and events: http://msdn.microsoft.com/en-us/library/ms178472.aspx .
In terms of MultiView - you should NEVER use Response.Redirect when you work with MultiView.
If user can not switch to previous view then you can check previous ActiveViewIndex value before setting it to the new value, e.g.
if (mv.ActiveViewIndex != newIndex)
{
// this view is displayed for the first time
}
If user can switch to the previous views, I suggest to place an information about already used views in session or by placing hidden field on the form with ids of the views that have already been displayed and to use that information instead of IsPostBack.

Categories

Resources