FlowDocumentPageViewer jumps be default to the last page - c#

I have a FlowDocument that has been populated with a bunch of tables. Then I do,
DocumentReader = doc;
(DocumentReader is a FlowDocumentPageViewer and doc is FlowDocument)
When I do this, the control jumps to the last page. I tried DocumentReader.FirstPage() but then realized that the PageCount is 1. (The FlowDocument is really long; I see hundreds of pages in the control. Except when it is loaded I see page 344 of 344).
How can I jump to the first page?

Try using this -
this.DocumentReader.GoToPage(1);

I also have encounted this thing.After checking the viewingmode of the flowdocumnetreader,i find that switching the viewmode from scroll to the page
will always set the first pgae as the current page .In fact, u can set flowdocumentreader's
visibility to visible until content inserting is completed to gain a decent UI transition.
this.docReader.ViewingMode = FlowDocumentReaderViewingMode.Scrol
this.docReader.ViewingMode = FlowDocumentReaderViewingMode.Page;
good luck!

Related

TabContainer goes Invisible when I make child tab visible = false

I've been struggling with this for a day. Not finding any others with my exact situation, so I figured I'd post and answer with what worked for me.
Environment: Asp.net 4.0 - AjaxControlToolkit v.7.1213.0
Problem: I have a TabContainer with 3 tabs, and based on a database value, I will make the 2nd tab invisible or not. My problem is that when I make that second tab invisible it makes the entire tabContainer invisible. When I inspect source, I can see the control is rendered on the page (tested in Firefox And Chrome), but there's now a style tag (visibility:hidden) that is coming from somewhere NOT in my code (master page, child page, style.css, c# codebehind files, etc), as far as I can tell. I have yet to find an explanation for this errant style tag. I'm not an ASP.net master, so it could be some idiosyncracy with my code, but it's also possible that this is a bug with AjaxControltoolkit.
I'll answer this with the workaround that is currently working for me.
Workaround:
Since I only need to remove / hide this from my users, I am able to use the Tabcontainer.Remove method. When using this method, my tabContainer no longer disappears after postback when it contains an invisible tab.
I replaced:
if(x.value == true)
tabpanel1.Visible == false;
with:
if(x.value == true)
tabContainer1.Tabs.Remove(tabpanel1);

Disable postback of certain properties of Telerik RadEditor control

We have a page with Telerik RadEditor on a tab strip. There are scenarios when RadEditor contains a lot of html and when doing a post back in order to switch the tab, all its contents is being post back to the server. This results in gigantic performance loss (there are times when post backs are sending tens of MiB of data).
Is it possible to tweak RadEditor in such a way that it does not send its contents over to server on postbacks? Our code-behind does not rely on RadEditors Content property accessor (does not read its content explicitly), only its mutator (its contents are set from within the control's code-behind).
Is it even possible to do such things with any of Telerik controls and if it is, then how do we achieve such result?
It's worth pointing out that we use relatively old Telerik UI version (2013.2.611.35) and we can't switch to a newer version at the moment.
Thank you in advance.
Consider using the ContentUrl of the PageViews. This will let you load separate pages in iframes, so they will postback independently of the main page. Thus, you can have a standalone page with the editor and standalone pages for your other tabs.
On the possibility to exclude something from the POST request - I don't know of a way to do this, as it is not supposed to happen. The whole point is to transfer the current page state to the server.
Another option you may consider is using AJAX and the PageRequestManager's beingRequest event to try to blank out the editor. I have not tried it and I do not know whether it will actually work out, since so much data may simply be too much for the JS engine to process before the postback begins. Here is a bit of code that illustrates the idea:
var currContent = null;
function BeginRequestHandler(sender, args) {
var editor = $find("<%=RadEditor1.ClientID%>");
currContent = editor.get_html(true);
editor.set_html("");
}
function EndRequestHandler(sender, args) {
var editor = $find("<%=RadEditor1.ClientID%>");
editor.set_html(currContent);
currContent = null;
}
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

Get print page count without printing the document

This is somewhat similar to question about Is there a better way to get the page count from a PrintDocument than this?
But in my case I have a web-browser control with formatted html. At the moment I have option which calls ShowPrintPreviewDialog() so user can see how many pages going to be printed.
Is there anyway to get the no of pages which going to be printed, without launching the PrintPreview?
I am trying to create a method which will call OnTextChange and display print-page count automatically?
I have use PrintPage event
private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(this.webBrowser1.DocumentText, this.webBrowser1.Font, Brushes.Black, 10, 25);
}
Bad news always travels slow at SO. You'll need to scratch the idea that this is practical.
Although unstated in the question, you should have already figured out by now that your PrintPage event handler doesn't work. It always produces a count of 1. That's because you never set the e.HasMorePages property to true, the property that causes more than one page to be generated.
To reliably set that property to true, you need to figure out exactly how the HTML gets rendered by the browser layout engine. And figure out exactly how to break it up into pages that don't cut, say, a line of text or an image in two. And figure out how to this is in the exact same way that the browser printing engine does this. A feat that's been attempted by many a programmer, accomplished by none. The browser's automation object model just doesn't have the needed api.
The only reasonable way is the one you already know. You have to call ShowPrintPreviewDialog(). Which readily displays the page count in the preview dialog, looks like this in IE11:
In case you'd consider snooping that number off the dialog: no, that cannot work either. The dialog doesn't use any controls, it is one monolithic window.

get current visible part of page displayed in IE

I'm working on a screen reader and till now I was successful to get the whole text of a page in IE. But I have no idea how to get the current visible part of page or to get the current paragraph that is under the cursor in IE.
I don't mean to give me the code, but just to recommend me if there is a way to do it using APIs or similar things.
from what I found I think it’s not doable using Accessibility APIs.
I GREATLY appreciate any ideas and helps.
If you're application is a WinForms app, you might want to look into using the Browser control. I'm still a bit unclear about what you're looking for, but I think the browser control is what you'll need.
Here's a similar question that may point you in the right direction:
C# WebBrowser control -- Get Document Elements After AJAX?
To access the contents of a paragraph when the cursor moves over it you could use javascript:
var oP = document.body.getElementsByTagName('p');
for (var i = 0; i < oP.length; i++) {
oP[i].onmouseover = function() {
var content = oP[i].innerHTML;
// Do whatever you want with content.
};
}
This will fire the onMouseOver event when cursor moves over a paragraph and you will then be able to read it's content.

Forms.WebBrowser strange behavour

I have a Webbrowser control that I am using to generate thumbnails of web pages.
Below is my code:
webBrowser.AllowNavigation = true;
webBrowser.Navigate(#"about:blank");
webBrowser.DocumentText = url;
if (webBrowser.Document != null)
webBrowser.Document.Write(url);
Where url is a string containing the html.
Using the above code results in webBrowser.DocumentText sometimes being populated with my html and othertimes not.
However I have found that line 3 and 5 are basically doing the same thing and webBrowser.Document.Write(url); is a much better way of writing the html to the browser, so I removed line 3 and it works everytime.
So my question is why by having line 3 does it cause it to fail occasionally, since line 5 is in effect making line 3 redundant anyway?
Docs for DocumentText say that
If you set the value of this property and then immediately retrieve it again, the value retrieved may be different than the value set if the WebBrowser control has not had time to load the new content.

Categories

Resources