Welcome Guest Search | Active Topics | Sign In | Register

BeforeNavigate event getting values of fields Options
Tom Wynne
Posted: Thursday, January 29, 2015 4:51:51 PM
Rank: Member
Groups: Member

Joined: 1/29/2015
Posts: 26
I am trying to extract values of form fields before the page navigates to the next one using the WebView control.
I get the following message when the BeforeNavigate event occurs:
EvalScript failed because It is not safe to run JavaScript code at this moment. This can occur if you are inside event handlers of certain WebView events. In that case please check CanEvalScript property before calling EvalScript.
My code is:
Private Sub WebView1_BeforeNavigate(sender As Object, e As EO.WebBrowser.BeforeNavigateEventArgs) Handles WebView1.BeforeNavigate
sValue = WebView1.EvalScript("document.getElementsByName('userID')[0].value")
End Sub

this also gives the same error:
sValue = WebView1.GetDOMWindow.document.getElementsByName("userID")(0).innerText

Is there any other way to get the value of the form fields before the page navigates?

Thanks
eo_support
Posted: Tuesday, February 3, 2015 4:06:17 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

I apologize for the delay. You won't be able to run JavaScript from within BeforeNavigate event. What you can do is to try to use a custom resource handler to catch all POST request and then examine the request object in your custom resource handler. See here for more details on how to use custom resource handler:

http://www.essentialobjects.com/doc/6/advanced/resource_handler.aspx

Thanks!
Tom Wynne
Posted: Thursday, February 12, 2015 5:13:24 PM
Rank: Member
Groups: Member

Joined: 1/29/2015
Posts: 26
How do I just intercept the values from the request object? Can I use the request object from the Match function, or do I need to use the ProcessRequest function? If I use the ProcessRequest function (returning True from Match), how do I just pass the request along without modifying it as in the example?
Thanks
eo_support
Posted: Friday, February 13, 2015 10:09:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

You won't be able to pass the request alone in your custom resource handler. As soon as you use custom resource handler and you return True from Match, then you MUST process that request yourself. Of course how to process this request is completely up to you. For example, it is possible that all you do is to just to create System.Net.WebRequest object based on our Request object and then populate the result into our Response object.

Another way you can do this is to use WebView.JSInitCode to inject your own JavaScript code into the page to intercept the form's submit method. This is a very common approach in many frameworks. For example, ASP.NET uses this to run the validators. You can do all the work in your JavaScript, or call back to your .NET code through JavaScript extension:

http://www.essentialobjects.com/doc/6/advanced/jsext.aspx

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!
iTester
Posted: Thursday, July 6, 2017 2:34:56 PM
Rank: Member
Groups: Member

Joined: 5/2/2017
Posts: 25
Hello,
In order to save the form fields (and to present them to user later) we wish to walk through collection of form's Input fields when page is about to change to new one.
In MS WebBrowser the _BeforeNavigate event is perfectly suitable for this.

However your post from February 3, 2015 4:06:17 PM on this page you suggest that in EO WebView old web page is not available in _BeforeNavigate event.

Is it still true TODAY? If it is the case, what is the BEST way to obtain the content of the Input fields immediately before the page replacement with another one?
Or your suggestion regarding resource handler from February 3, 2015 4:06:17 PM is still the BEST solution?

Thanks!
eo_support
Posted: Saturday, July 8, 2017 9:36:52 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

It is still true that you can not call EvalScript inside WebView.BeforeNavigate event.

The best way to do the kind of interception you need is to handle WebView.BeforeRequestLoad event. Inside the request you will use e.Request.PostData to examine the post data. Note that:

1. The items in PostData collection is encoded. For example, if you have three textboxes, then all three will be encoded in one PostDataItem with application/x-www-form-urlencoded data that contains all three fields;

2. Do not use debugger to watch PostDataItem.Data. This field is lazy populated and it will not be evaluated successfully in debugger;

Please let us know if you have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.