Detect webBrowser document changes after DocumentCompleted has been fired - c#

I am using a WebBrowser control. I edit some HTML inputs and click a button in the WebBrowser DocumentCompleted event handler. My problem is clicking the button I mentioned changes the content of the Document using AJAX, Knowing that I need to parse some information from the new changes. The question is: How can I detect when the document has finished loading the new content. Is there any sort of an event handler like DocumentChanged.
Thanks in advance.

I figured you'd be back about this. The extensibility object model has no great support for observing scripting execution. It isn't practical, scripting code can run completely asynchronous from the page state at unpredictable times. If there are no reliable DOM modifications made by the script that you can read back then you have no great options beyond just spinning your wheels for a couple of seconds to give it 'enough time'. Shouldn't be a problem given that you run this in a worker thread, just use a System.Windows.Forms.Timer who's Tick event calls Application.ExitThread to end the thread.

No way to do that, I'm sure - WebBrowser control is very simple and poor-functional

Do you control the HTML of the document you're displaying ? If so, after the ajax changes have completed you can use Javascript to call a C# method in your parent form window.external.MyPublicMethodName() instead. Your app needs to be running in Full Trust for this to work, and also to have set the browser ObjectForScripting object to the form itself e.g. this.webBrowser1.ObjectForScripting = this; in your Form_Load event.

Related

Is there an event called after a gridview is completely finished?

Or a way to detect it is finsihed rendering?
Actually almost exactly this question
Gridview, is there an event, how would I determine that it has finished being rendered?
but he does not state exactly how he detected that everything had been drawn/resized.
EDIT: (Adding my comment from below to specify what i am trying to do)
I am trying to create a work around for static header for a gridview by basically dynamically adding another gridview above the one that actually has the data in it. I resorted to this after trying about 12 different suggestions/solutions with no real luck. What i have works pretty well except that the new header is rendered before the one with the data in it completes its re-sizing, I realize what i am trying might not even work since it might require another postback to re-render the new one after i find the sizes of the column headers but thought i might get around that with an update panel.
I realize this might not be the most elegant solution but honestly have yet to find any solutions to this problem that come even close to elegant or have even worked correctly with current browsers.
It renders at the client so the server doesn't know what is happening there.
You are probably looking for the DataBound event.
Otherwise, at the client, you can determine when the page has finished loading (the jquery ready function) and then call back to the server. But I can't imagine anything useful you could do. If you send more data to the client and it renders again, you could have an infinite loop.
Everything in an ASP.Net webpage is rendered at the same consecutively at the same stage of the lifecycle (see http://msdn.microsoft.com/en-us/library/ms178472.aspx), so the Gridview will be rendered between Gridview_PreRenderComplete and Gridview_Unload.
You page PreRender will fire, then the control PreRender, then the page will call the Gridview Render method (there is no event for this) then the control Unload will fire and then the page Unload will fire.
Other posters to this question are referring to the client side rendering whereas I am referring to the server side rendering process. Which is it that you are actually after and why please?

How to add a popup textbox for submitting a message - Windows Phone

Shame I have to install another toolkit, but this seems to be pretty useful: Coding4Fun InputPrompt.
I am having an issue with it though:
There only seems to be functionality for triggering an event when the input is 'completed' without being able to differentiate between whether the tick is tapped or if the cross is tapped.
Rushed into asking for help unnecessarily there. Found a solution, will post below.
Original question:
Users of my application can currently submit messages which they do by tapping on a textbox and typing in the message and then tapping send.
I want to make this cleaner by not having a permanent textbox for this and instead have users tap on a button on the application bar along the button which brings up the keyboard along with a textbox to type into, and when users tap submit the textbox and keyboard disappear again.
I can't see any way of creating a popup with a textbox in it, so how would I do this?
I'm using the WP Toolkit already for a messagebox with a ListPicker inside, by even this toolkit seemingly has no way of adding a textbox.
I'm not sure what your trying to do is even possible. However, what you could do is have a Parent Form which contains your ideal Interface. Within this Parent you could create an Event Handler that is listening for a response.
Then when it comes to that Textbox it actually creates a Child Form or Page. Which they can input their value into. Then the page automatically closes, which then the Event Handler will already know the change for you to manipulate with the rest of your Logic.
As mentioned above, normally you would go to another page. I don't know if my solution is viable, but it does accomplish your goal. I'd recommend possibly refactoring your interface so that it makes it slightly more elegant. That way your logic handles it more elegant as well.
Hope that helps.
Shame I have to install another toolkit., but this seems to do the trick just fine: Coding4Fun InputPrompt.
They've added input.IsCancelVisible = true to add a cancel button and then use e.PopUpResult.ToString() == "Ok" within the input_completed method to only submit when the tick button is tapped.

Why WebBrowser.Document.DomDocument doesn't contain the actual DOM model?

I use WebBrowser.Document.DomDocument and found that it has different DOM model that I can see in IE Debug Tool.
IE Debug Tool contains the valid actual DOM model while WebBrowser.Document.DomDocument doesn't contain some elements added dynamically by JavaScript.
Actually the WebBrowser control displays all elements, even those that were added dynamically, but WebBrowser.Document.DomDocument contains outdated DOM model.
IE Debug Tool can display the actual modified DOM model at it's current state, how to get the current DOM model using WebBrowser component?
There definitively should be a way to do it.
This question could use better documentation. But this is a pretty classic problem, it is a timing issue. You no doubt access the DomDocument property too early, typically you'd do so in the browser's DocumentCompleted event. That's roughly the time the javascript code starts executing. So you'll get the version of the DOM before the changes made by the script.
There's no decent way to deal with the problem. Execution of Javascript is entirely asynchronous and there are no events to indicate any scripting code started or stopped running. The only decent thing you can do is "wait a while", use a timer. Preferably repeatedly until you see a good indication from the DOM that the script is done making its changes.

Textbox KeyDown Event in Visual Web Developer

I am trying to implement a KeyDown event for a textbox in Visual Web Developer. I am using C#. I know how to do this in a windows form but the technique isn't portable to VWD. I want to capture the text in the textbox when the user hits Enter.
Any advice is appreciated.
Regards.
Sounds like you may want to read up a bit on Web forms in general. A quick summary:
Since web pages are all client side, you have to explicitly tell it when to talk to the server where all the major lifting takes place.
So you have the html form tags:
<form>
</form>
and all important text boxes and other form controls go between.
Then you need a submit button which under normal circumstances is the only way to submit the form to the server for processing. (The "enter" key activates the submit key also.). Submission always either reloads the page or causes a move to the next page, depending on the actions specified.
ASP.NET does take care of a lot of page events and such for you. as you have probably noticed by now, though, when you right click a text box and look at the available events, you only have a few, such as "textchanged". This is because anytime you do not actually submit a form to the server, you need AJAX to do a call to the server for you while not reloading the page. the "textchanged" event on a textbox is still going to be AJAX driven - it's just the Microsoft has built it in for you. You will want to look at either jQuery or the ASP.Net AJAX libraries.
You say you want to "store" the result - is it to generate new behavior later on the page? that's AJAX. Is it for longevity while the entire application is worked through? That can wait until the submit.
Actually the textChanged method waits for the Enter key to be hit.

to show loading while navigating a web page using c# .net browser

hiii
I am developing a window application in which I am showing a web page using c# .net browser. since my web page is quite heavy and its taking time to load . so i want to show loading image while navigating a web page .so tell me how should i do .
I assume that you are using the WebBrowser wrapper, is that correct?
You can use the ProgressChanged and/or Navigating + DocumentCompleted events.
As an asside:
Depending on the nature of your application you could pre-download parts of the page to improve the user’s pereption of the app’s responsiveness.
It may sound overly simple, but it might be the easiest solution to just add an image control with an animated bitmap to the form at runtime when the page starts loading. Once it's done, just hide the image again. This would also give you the flexability to display any messages you want and add effects/transitions to make it aesthetically pleasing.
Only since you asked so nicely.
You could just do this by monitoring both the navigating and the documentcompleted events of the webbrowser control. (Im sure you can fill in the blanks here).
Be sure when you use the documentcompleted event that you check the readystate :
theBrowser.ReadyState == WebBrowserReadyState.Complete
Otherwise the documentcompleted event will fire multiple times even before the entire page has loaded.
First create an image(give a name for it) and place it wherever you want it but make the Visibility to Collapsed.
Then in your browser_Navigating, add this code, ImageName.Visibility = Visibility.Visible;
and then in your browser_Navigated, add this code, ImageName.Visibility = Visibility.Collapsed;

Categories

Resources