WebBrowser and javascript

后端 未结 1 692
既然无缘
既然无缘 2021-01-25 11:26

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

相关标签:
1条回答
  • 2021-01-25 11:46

    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.

    0 讨论(0)
提交回复
热议问题