1

I am working with a website that has javascript that does some changes on the page load. However, when I load the page and handle the DocumentCompleted event, this change isn't there. If I then continue paste the DocumentCompleted event, I can see the change happen. However I need this change to happen during DocumentCompleted so I can check some things.

Is there an other event I can subscribe to, or a way to cause the webBrowser to do all the javscript on page?

Edit: This is what I am talking about.

I loaded a sample page just to show you, and clicked the submit button with all fields empty to generate an the error.

Here is the result:

http://s8.postimage.org/zfv6stcar/sfsdfsdfds.jpg

Now if I take the HTML at that precise moment from that WebBrowser control, and render it somewhere else, those errors go away. The same thing happens when the server sends back those errors. If I handle the DocumentCompleted event and take the html, it isnt there. But after the event, it shows up in the control.

Hope you understand, it's hard to explain.

TheGateKeeper
  • 4,420
  • 19
  • 66
  • 101

1 Answers1

1

The problem seems to be that the DocumentCompleted event is being fired before the javascript. You should do some reading on how client side/server side things function.

One option is to make a separate method for the DocumentCompleted event and call it form the javascript after it has been completed. This would get the sequencing of these events working properly, but is not very ideal.

Alternatively, you could call the javascript code at the beginning of your DocumentCompleted event. The link below gives a pretty good explanation of how to go about that.

http://forums.asp.net/t/1117189.aspx/1

Personally, I would avoid using javascript and do the validation on the client side .NET, but I don't know enough about the website to really say.

EDIT:

This should be the script you are looking for. Alternatively here is a thread related to your issue. Sorry I don't have the exact code as I don't have a project to test this on.

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx

Calling JavaScript Function From CodeBehind

RE-EDIT:

What is happening on the link you provided in the comments, is that each textbox is calling some javascript as well as the submit button. The best way to examine this is using the "Inspect Element" in the right-click menu on Google Chrome. For example, doing this on the textbox would show that it is registered with a few events:

onfocus="$('f_tip_Username').style.display = 'inline'"

onblur="$('f_tip_Username').style.display = 'none'"

onchange="$('f_err_Username').style.display = 'none'"

The first the element with the ID 'f_tip_Username', sets the display style of that element to inline (visible).

The submit button calls the following:

onclick="return o_edit_profile_form.validate()"

Doing a find on "o_edit_profile_form" in the source code, you can find the exact javascript location that is being called. Enjoy!

FINAL EDIT (hopefully?):

Follow these steps: go to your site, right click and go view source. Do a find for "f_tip_Username". This is the ID of one of the div tags being used. The third entry of it, should be a "div tag" that is used under the first textbox to warn of "min 3 characters".

You'll notice above that in the code is a input type "text" with the Name "Username". Notice the three events it has registered in it:

onfocus="$('f_tip_Username').style.display = 'inline'" 
onblur="$('f_tip_Username').style.display = 'none'" 
onchange="$('f_err_Username').style.display = 'none'"

These either hide or make visible, the div tag we found (f_tip_username) and also a separate div tag (f_err_Username) which is the error message div tag. Let me know if you are not able to find these in the source. Follow the steps I provided and you will find it in the "view source" OR in the DocumentText.

Community
  • 1
  • 1
ImGreg
  • 2,946
  • 16
  • 43
  • 65
  • Yes this is exactly what I need to do! But how can I call the validation function? – TheGateKeeper Mar 07 '12 at 19:32
  • @TheGateKeeper see my edit. Should give you the direction you need. – ImGreg Mar 07 '12 at 19:44
  • Hi mate, I know how to call it, but I dont know what to call. Here is the page I am referring to. Can you show me what the method is called? http://www.4ppl.com/join/form – TheGateKeeper Mar 07 '12 at 20:31
  • I don't understand the question @TheGateKeeper. You don't know which javascript method to call? Very hard to look at your code from the "ViewSource". Lots of iframes and other messy code. That and I have no idea what the site/javascript actually does/is supposed to do. I recommend searching through the code for the "javascript" and examine each – ImGreg Mar 07 '12 at 21:31
  • Its a little hard to explain... please bear with me as I have been trying to solve it for ages. I updated the main question, please check it. – TheGateKeeper Mar 08 '12 at 00:11
  • No problem @TheGateKeeper. I understand what is going on now. I will edit my answer. – ImGreg Mar 08 '12 at 03:20
  • You dont understand man, I CAN get them to show up by clicking the button, but when I look at the html they arent there! Try it, go on the webpage using firefox and click the button with all fields empty. Then look at page source for the errors, they arent there! – TheGateKeeper Mar 08 '12 at 09:57
  • I just decided not to use website with javascript. I have no problem working with ones without it. Guess I just don't know how. – TheGateKeeper Mar 08 '12 at 14:05
  • The error messages are on the page. I just looked at them. For example, the error message on the first text box is in a div tag with the id 'f_err_Username'. Use chrome to "inspect elements". It will make things much more clear for you. Firefox doesn't have the capability. View Source = uber confusing. – ImGreg Mar 08 '12 at 14:16
  • I too tried this, and you are correct it is on the page when inspecting the elemenets. But as mentioned before, it doesn't exist for some reason in the view page source. – TheGateKeeper Mar 09 '12 at 11:42
  • Now when accessing the page programmatically, and call the DocumentText, you will get the same resuly as "view source". Know what I mean? You can try it out using a test WebBrowser control, I tried for some hours couldn't get it. – TheGateKeeper Mar 09 '12 at 11:43
  • I have edited it again. Follow the steps specifically and you should be good @TheGateKeeper. – ImGreg Mar 09 '12 at 14:22
  • 1
    Either I am not understand you or you are not understand me. Let me try to show you again. Lets take another site, like this: https://www.350.com/signup Click the button with all fields empty, and the errors come up. On inspecting the elements, the source for the first errors is: Please enter a username with at least three characters However, if you go in the view page source, the div is still hidden. Know what I a mean? I think javascript changes on the site do not show on src. – TheGateKeeper Mar 09 '12 at 18:21
  • 1
    Sorry @TheGateKeeper I have been misunderstanding your question for a while. Sorry! View this thread here for further info. http://stackoverflow.com/questions/1896708/firefox-view-source-code The gist of it is that the "view source" shows the server side code (the code you got when you first loaded the page). You want to "view source" after javascript changes, which cannot be done too simply. – ImGreg Mar 09 '12 at 18:30
  • Ok, atleast I know am not crazy now! And I understand why people like me hate javascript so much! Good thing 5/10 websites don't use it, so it's just a matter of filtering it out. Thanks dude, I marked you as answre ;) – TheGateKeeper Mar 10 '12 at 10:27