Html code from GeckoWebBrowser.Document.DocumentElement.InnerHtml property differs from html downloaded from server because it is converted to DOM and there could be Javascript that changes document structure.
How to get real page source?
There's a method for that:
GeckoWebBrowser.ViewSource();
or
GeckoWebBrowser.ViewSource(string url);
Opens a new window which contains the source code for the current (or specified) page. If you just want the text, try:
GeckoWebBrowser.Navigate("view-source:" + url);
I have a new way to fix your problem like that:
GeckoWebBrowser1.Navigate("about:blank")
Me.Delay(1) Make your function to wait 1 second here
GeckoWebBrowser1.Navigate("view-source:" + "YourUrl")
Related
I am trying to create a C# string builder that will later build an html page based on information in a database and user input.
What I am having trouble with is creating two buttons in the string where one button redirects to page a.asp and the other button redirects to b.asp
I have tried multiple methods but none seem to work. Here is my latest version of code but I might be way off track:
in my page.asp.cs file:
responseString +=
"<div>"
+"<table><tr>"
+"<td><button id='submitSave' type='submit'>Save</button></td>"
+ "<td><button id='continueBatch' onserverclick=\"OnClickButton\" type='submit' runat'server'>Continue Batch</button></td>"
+ "<td><button id='submitDelete' onclick='confirmDialog()' type='button'>Delete</button></td>"
+ "</tr></table></div>";
and it points to the method also in page.asp.cs:
public void OnClickButton()
{
//Redirect to New
Response.Redirect(String.Format("New.aspx?fmtypeP={0}&formverP={1}", FormTypeS, FormVersionS));
}
and last but not least I have in the page.asp page the following:
<form action="save.aspx" method="POST">
I know the form action will need to change but I just wanted to let you know I currently had it in place.
Am I working in the right direction? Is there an easier way to accomplish my task? If not what am I doing wrong?
I would rely on ajax to solve this problem if possible. One solution would be to use onclick and call an existing javascript method like you seem to have done for the confirmDialog() on the delete button. Maybe use jquery's wrapper for the ajax call: http://api.jquery.com/jquery.ajax/. Let the server method return the redirect link and use window.location = the return value in the success-method.
Or if you know what the redirect links should be when building the string you can make the redirect directly: onclick='window.location = "your redirect link"'
You can not use server-side controls like that. In your code they just added to response stream and not being compile and stuff. You need to add controls to your aspx page or add them in code like actual controls via new(), not like strings.
In my app I want to load an html that contains an iframe with a remote url. This html is always the same, except for the iframe's src. What I do is hold the html in a string, and fill in the iframe url, than call NavigateToString(html). I get the iframe url from a REST API. I also get a baseUrl. If I merge those two urls into an absoulute url and set that as the iframe's src, the page won't load due to security reasons (it's a payment page). But if I set it without baseUrl, of course, the webview has no idea what's the baseUrl is, and the page also won't load.
In Android one could simply call webView.loadDataWithBaseURL. Is there something like this in Windows Phone 8.1? Any workaround?
(The problem is further complicated by that I also have to set Cookies to the webview.)
I came up with a solution, which works, and actually it's less hacky than it seemed to me at first.
I skipped NavigateToString. By using NavigateWithHttpRequestMessage, I can send a request to an URL, for example http://mybackend.com. I can set cookies as well (more information on this: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/a451d411-9312-4d40-80ee-112e166144ab/how-to-send-auth-cookie-in-webview-request?forum=winappswithcsharp). So far I have:
base URL set
cookies set.
Though, I haven't set my local html string yet. For this, in the WebView's NavigationCompleted event, I run a JS script like this:
await wvSecurePay.InvokeScriptAsync("eval", new string[] { "document.getElementsByTagName('html')[0].innerHTML = '" + htmlToLoad + "';"})
This will replace the current html content with the one I want to load. So I have my html containing the iframe with the relative url on a page which has the domain I need.
I have a WebBrowser on my form and once the page is loaded and some content is extracted, I call Refresh() method but I'm getting this error from page:
How can I confirm this resubmission automatically and programmatically?
Note on buttons' text translation:
Repetir = Repeat
Cancelar = Cancel
If it's an option, try doing an AJAX post and checking on the response.
Could you simply change the URL in the WebBrowser to the same page, rather than refreshing?
If all you are doing is trying to load content, rather than actually displaying something - you could try Watin. http://watin.org/
I want to assign the html content to iframe control from asp.net code behind page;
this is working fine
myIframe.Attributes.Add("src", "pathtofilewith.html");
but, i don't want to give the path of html file to display i just want to assign some html content which comes from database to iframe control.
i want some thing like this(Ashok) to be displayed in iframe control
i tried the bellow ways but nothing is succesful
myIframe.Attributes["innerHTML"] = "<h1>Thank You..</h1>";
myIframe.Attributes.Add("innerHTML", "<h1>Ashok</h1>");
A way to communicate between two different pages where one is in an IFrame on the other, is to post data using JQuery. An example is given in this StackOverflow question
It is also discussed in this other StackOverflow question
On this page, you will also find a short and simple example of how you can put content in an IFrame without using a separate web-page for it (note the lacking src attribute!).
Hope some of this helps!
You can't. That's not how an IFRAME works - it is for use with the src attribute as you've already discovered.
Perhaps you want to create a DIV instead
There is no way to insert HTML content into iframe tag directly, but you can create a page which gets the content form the database and then you can view it using iframe,
or
You can create a page for example called getContent.aspx which request value from the URL e.g. getContent.aspx?content=<h1>Thank You..</h1> and display it wherever you like, and then call it from iframe.
What is the best way to show the server-side generated HTML (full page) into a new popup window? It should be triggered upon clicking a button (causing a postback to the server).
Thanks
Edited:
The HTML content are dynamically generated in the code behind and the content is full page (<html> ... </html>). Upon clicking a button on the web page, I would like to get the generated html content and pass it to the browser and show it in a new popup window. The content will be the final result (UI) not HTML tags.
You can send the same page with mime type text/plain
For instance with a
<a href="same url?mime=textonly" target="_blank">
On the asp server, when the argument mime=textonly is detected, you change the mime type to text/plain
Perhaps I should have started with a comment to get more information but can you not:
Post back to a new window on click? <a target="_blank">
Though if the requirement is for the server to generate the new window, just append something like:
<script>window.open('title'); </script> at the end of the response and have the server populate that.
You could probably have the server code save the HTML to a file and output <script>window.open('urltothefile');</script>. Just make sure that you write a unique filename each time.
Alternatively, you could have the server code store all related information into a database and output <script>window.open('showResult.aspx?id=123');</script>, where 123 is the id of the database record. Then in showResult.aspx, have it generate the required HTML.
Another option is to output the HTML into a div with style="display: none", then have some javascript to assign the innerHTML to the newly opened window. eg:
var w = window.open ('_blank');
w.document.body.innerHTML = document.getElementById("returnedHTML").innerHTML
One more possibility is to have a WebMethod. I don't really remember how to declare one, but it is a server function that can be called from the client. Open the window via javascript, call the webmethod and place the result as the innerHTML of the newly opened window; Pretty much like the previous option.
All these are good but they don't work when you use UpdatePanel and partial rendering. If that's the case, it's a whole different story.