WebPage Render Position Controller - c#

First question but I really am in a jam.
I have a webpage render which is working perfectly. However, I need to be able to control the initial display position (almost like a href #anchors in HTML) but without any access to the site content.
From as far as i can see i have no access to the scrollBars other than the bool to enable / disable..
Is there anything i can do to even force a scroll down of 20% for example, and then I can create a form to adjust later on.
Any assistance would be HUGELY appreciated although from what I have researched it seems unlikely.
I have the regular windows WebBrowser Render
private System.Windows.Forms.WebBrowser m_webBrowser;
Thanks !
--This is for c# standalone application.. Not WebBased.

Have you tried using jquery?
I personally use the animate method from jquery to scroll to certain elemnts in my webpage.
Example:
$('html, body').animate({scrollTop: $('#the-element-you-want-to-scroll-to).offset().top}, 1000);
PS: For the last parameter you can control the time it will use to scroll to destination, that offering you a nice effect.(in milliseconds)

I managed to resolve it using a strange method..
I basically injected some javascript into the rendered HTML manually.. Then the rest was easy.
i used something like this :
string updatedSource = WebBrowser.DocumentText.Replace("Google", "Foogle");
string extraSource =
"<html><body>Script goes here <br/>" +
"<div><p>BLA BLA BLA</p></div></body></html>";
WebBrowser.DocumentText = extraSource + updatedSource;
WebBrowser.Update();
Maybe it will help someone.

Related

set leaflet zoom region from C# codebehind

I have an ASP.NET page using a leaflet map. I have a filter being applied to some map icons.
When I apply the filter, which is an ASPX control. when the result of the filter comes back, since ASP resends the entire page back to the client, i loose the current zoomed in region I was looking at.
I have saved off the values of the last bound coordinates the user was looking at but exclude the possibility of the most zoomed out case since that's what i'm trying to avoid. I'm trying something like
string temp = "<script language=\"Javascript\">
myMAP.fitBounds([[RA[0],RA[1}][RA[2],RA[3]]);
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "resetZoom", temp);
but I'm still seeing the map get reset like when the page gets sent back. am I calling the wrong leaflet method or is there a better way to implement what I'm trying to do? Please advise...
.fitBounds() method is having a coma between points, so I will be something like this:
.fitBounds([
[RA[0], RA[1]],
[RA[2], RA[3]]
]);
(source)
Is it fixing your problem?

Redirect the page with Height & width

i have a doubt that i can redirect the page , but can i put height and width there
response.redirect("Mypage.aspx");
for eg
response.redirect("Mypage.aspx",height="300px",width="200px");
i am doing this in asp.net, c#
You cannot open a page with this method, use javascript window.open instead.
ClientScript.RegisterStartupScript(this.Page.GetType(), "", "window.open('Mypage.aspx','mywindow','menubar=1,resizable=1,width=300,height=200');", true);
dude, you quite lost... I suggest you to understand the server side concept of web application first, otherwise the learning asp.net experience could be frustrating...
regarding your question, there is not such thing what you want to do, the display on the page is html format in the client side (applying style(for example) to html elements )
although you can map those html ui in the server side

Get Frame Source from WebBrowser Control

I wrote up a function to save sites source as my WebBrowser control navigates around. I cant save only the WebBrowser.DocumentText as that leaves out all frame content.
The issue I'm having now is accessing the frame content - I cant find which method/property contains it.
The following works with a simple WebBrowser control, simply put saveWebsite(FilePath, WebBrowser1) in the DocumentCompleted event.
Ive done this in VB.NET but am familiar with C#, so C# solutions good too
Public Sub saveWebsite(ByVal sDirectory As String, ByVal oBrowser As WebBrowser)
File.WriteAllText(sDirectory & "index.htm", oBrowser.DocumentText)
'Now write a file for each frame - putting each file in its relative path'
For Each oFrame As HtmlWindow In oBrowser.Document.Window.Frames
oFI = New FileInfo(sDirectory & oBrowser.Url.MakeRelativeUri(oFrame.Url).ToString)
oFI.Directory.Create()
'ISSUE: This is the issue, unlike with oBrowser, there is no DocumentText property for oFrame.'
'ISSUE: Ive tried several things like Body.InnerText/Html, Body.OuterText/HTML, etc.'
File.WriteAllText(oFI.ToString, oFrame.WindowFrameElement.InnerText )
Next oFrame
End Sub
After more experimenting, I just found a solution. However its dirty and I dont particularly like it.
Switching the last/issue line from oFrame.WindowFrameElement.InnerText to oFrame.Document.All.Item(0).OuterHtml seems to do the trick sometimes. This wont do anything about nested frames, but Im not really worried about that.
Anywho, if anyone has a cleaner solution to the above, please let me know. (Or even a more effective/efficient way of "saving all").
Edit: The following seems to work a bit better, but still not great. (I had a webpage that started with <% VBSCRIPT %> and thats all that got saved) oFrame.Document.GetElementsByTagName("html").Item(0).OuterHtml
I was also facing simlar problem, I wanted to acess all the text contend within a Frame in a page. Below code worked for me
Dim frame = WebBrowser1.Document.Window.Frames(0) //Replace 0 with frame id if needed
Dim innderdiv= frame.Document.GetElementById("divContentLower")
Dim contents = innderdiv.InnerText
MsgBox(contents )
Here divContentLover is the id of an immediate child div within the frame. So the code returns its contents

taking a screenshot of some element in the html

So I was wondering, if I have a div which contains a maps of google maps rendered with some makers and I want to take a picture of that element how can I do this?.I found this solutions it's a approach of what I need but the problem it's that sending a url doesn't help me, I need the specific Div with all the markers. For the server side i'm using C# and for the cliente, asp.net with jquery. Also the google maps apiV3 to handle the maps
Take a look at the Canvas2Image library by Nihilogic Labs:
http://www.nihilogic.dk/labs/canvas2image/
Here's an example of how to take a screenshot of an element through JavaScript:
var oCanvas = document.getElementById("thecanvas");
Canvas2Image.saveAsPNG(oCanvas);
EDIT
You might also take a look at Html2Canvas and FlashCanvas too. I believe one of them has support for earlier browsers (those which don't support HTML5).
Use the method in the link you mentioned and crop the resulting image to the dimensions of your div. You can use myDiv.getBoundingClientRect() in JavaScript to get the dimensions of your div.
Using the WebBrowser control, you can manipulate the document using html or JavaScript to get the page in the state you need to take your screenshot.
Have you considered using the Google Maps Static API - this will render a map image, with markers on it, as a PNG.

show progress image while loading asp.net page

I have an asp.net page, with couple of Divs, some of these div's get the image path from database and show the image in a smaller version (thumbnail). and as soon as user click on thumbnail, I use ajax Modal popup to show the full size image, what I need to have is to have a progree image(gif), on every thumbnail image while loading the asp.net page for the first time, I konw that it is possible to use UpadePanel, but I need the actual working code,or any other way to achieve this,
Thanks in advance
Well, if you are posting back, udpate panel can work; but you can programmably in JS do this yourself, or also consider using a JS plugin like lightbox: http://www.huddletogether.com/projects/lightbox2/
Which has that feature and looks very cool.

Categories