I'm trying to add a page number to the bottom of the page, which doesn't seem to work as expected.
Currently i'm using this:
<span class="page"></span>/<span class="topage"></span>
The problem with this solution is that it doesn't count the cover as a page.
So a 7 page PDF "has" 6 pages according to my code.
I'm looking for a way to include the Cover as a page, so the number is correct.
Currently i'm looking into some JS to manipulate it afterwards, but there have to me some "official" solution?
Solved using javascript. :)
If anyone are looking for the solution here you go:
var x=window.location.search.substring(1).split('&');
for (var i in x) {
var z=x[i].split('=',2);
vars[z[0]] = unescape(z[1]);
}
var pageNumberStart = parseInt(vars.page);
var pageNumberEnd = parseInt(vars.topage);
if (pageNumberStart != null && pageNumberEnd != null) {
document.getElementById('page').innerHTML = pageNumberStart + 1;
document.getElementById('topage').innerHTML = pageNumberEnd + 1;
}
Maybe someone got the official way to do it? :D
Related
I'm trying to access a page in Word by it's name or number. I thought I was going in the right direction but there doesn't seem to be a page.name or page.number property. The issue is in my if statement where I'm trying to say if there is a page named Page 4 Content then select it.
var wordApplication = (word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
string path = CommonMethods.getFile(fileName);
myDoc = wordApplication.Documents.Open(path);
wordApplication.Visible = true;
wordApplication.WindowState = word.WdWindowState.wdWindowStateMaximize;
word.Pages pages = myDoc.ActiveWindow.ActivePane.Pages;
foreach (word.Page p in pages )
{
if (p.)
{
}
}
As you already mentioned there is no number or name property on the page object.
In order to get the page number you have to access the Information property of a Range or Selection object on that page.
In addition to that I recommend to study the article Selecting or referring to a page in the Word object model by Shauna Kelly. In her article she explains in detail why it is often not a good idea to rely on the page object for automated document processing. The reason for that is that Word uses a flow layout instead of a fixed layout. In order to determine the current page rendering Word has to talk to the current printer driver. This means that your page breaks may vary depending on your printer.
I ended up doing the following and it works like a charm.
object What = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object Which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute;
object Miss = System.Reflection.Missing.Value;
word.Pages pages = doc.ActiveWindow.ActivePane.Pages;
for (int i = 0; i < pages.Count; i++)
{
if (i == pageNumber)
{
doc.Application.Selection.GoTo(ref What, ref Which, pageNumber, ref Miss);
}
}
}
I am using the GeckoFX 22 c# web browser control but cannot manage to access tags within an iframe. When I check the gecko innerhtml it seems that although the iframe tag shows in the html, the contents of it do not.
This is the code I used to get the inner html of the browser control which just shows the iframe tag as empty (when it should have another doc inside of it):
GeckoHtmlElement element = null;
var geckoDomElement = webBrowser.Document.DocumentElement;
if (geckoDomElement is GeckoHtmlElement)
{
element = (GeckoHtmlElement)geckoDomElement;
var innerHtml = element.InnerHtml;
}
Previously I used code similar to the code below to access individual elements which works fine:
GeckoDocument checkDoc = (GeckoDocument)webBrowser.Window.Document;
var x = (checkDoc.GetElementsByTagName("a").Where(b => b.Id == "ipt-form-format-aside").First());
I am able to get individual elements and change their values/trigger events etc without problems with the main html document but anything in an iframe is impossible to get the elements of. I think perhaps the Iframe has not been loaded yet or something like that. Is there a way to force the control to wait for the I frame to load before attempting to access its elements?
string content = null;
var iframe = webBrowser.Document.GetElementsByTagName("iframe").FirstOrDefault() as Gecko.DOM.GeckoIFrameElement;
if(iframe != null)
{
var html = iframe.ContentDocument.DocumentElement as GeckoHtmlElement;
if (html != null)
content = html.OuterHtml;
}
I'm just posting this for anyone else that might get this problem
foreach (GeckoIFrameElement _E in geckoWebBrowser1.Document.GetElementsByTagName("iframe"))
{
if (_E.GetAttribute("class") == "testClass")
{
var innerHTML = _E.ContentDocument;
foreach (GeckoHtmlElement _A in innerHTML.GetElementsByTagName("input"))
{
_A.SetAttribute("value", "Test");
}
}
}
I got a similar problem so i did this
checkDoc.Window.Frames(1)
instead of
checkDoc.GetElementsByTagName("iframe")
value within the parenthesis (i.e. 1 here) depends of your index
In my application I'm showing a javascript pop up with a web page in it with the help of the following code:
popwin = window.open(URL, '" + id + "',
'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,
height=600,left = 262,top = 84');
which is giving me the required pop up with the web page in it.
I want to know whether there is any way to remove user interaction from this pop up and to remove the close button as well.
I will close this pop up using some timer ,but i don't want that user to be able to control the pop up. Is there any way for it?
I googled a bit but haven't got the relevant way to do it.
Note: Can i do this using Modal Pop Up?
Please suggest any good ways .
You can try following code.
popwin = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750, height=600,left = 262,top = 84');
SetTimeOut(function(){ popwin.close()},2000);
Here '2000' is time in milliseconds. 2000 ms = 2sec.
Let me know if any error occurs.
You can try Telerik Radwindows.
You can load your content in a Fancy Box and customize the fancybox as per your needs.
I think it could be more appropriate to use a CSS-like popup instead.
Working example:
http://www.pat-burt.com/csspopup.html#
As for your timer you could change the css attribute with your timer or use some jquery framework plugin like impromptu:
http://trentrichardson.com/Impromptu/
Which cost less time to deploy than the css solution I think.
hey man this is my popup. its not a window but acts like a window and is in jquery and javascript both.
$("document").ready( function() {
var link = ""; // your link here
var d = document.createElement("div");
d.style.display = "block";
d.style.border = "1px solid #282828";
d.style.background = "#ffffff";
d.style.width = "750px";
d.style.height = "450px";
d.setAttribute("id", "popup");
var m = document.createElement("iframe");
m.setAttribute("src", link);
m.style.width = "750px";
m.style.height = "450px";
m.style.border = "0";
document.body.appendChild(d);
d.appendChild(m);
var s=0;
var n = setInterval( function() { s=s+1; if (s == 5) {
$("#popup").remove();
} }, 1000);
});
http://jsfiddle.net/APKTX/
Wondered if it's possible to iterate through the pages held in the pages library and determine the page layout being used by each page? any c# code examples appreciated.
Many thanks in advance
You can get a reference to a PublishingWeb object and throught that the PublishingPage object which has a Layout property.
Below I have butchered the two pages example code to get something close to what you need.
using (SPWeb web = site.OpenWeb(HttpUtility.UrlDecode(webUri.AbsolutePath)))
{
PublishingWeb pWeb = null;
if (!web.Exists || !PublishingWeb.IsPublishingWeb(web))
{
return;
}
pWeb = PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection publishingPages = publishingWeb.GetPublishingPages();
foreach (PublishingPage publishingPage in publishingPages)
{
//do something here with publishingPage.Layout
}
}
Here's the deal. Have a functioning web app using ASP.NET WebForms with a C# backend. The thing works fine, but I'm always looking to improve, as a beginner at this stuff. Right now, to deal with a user's search coming back with no results, I utilize the following, and was wondering if there was any cleaner way to do it, for future reference:
DataClass data = new DataClass();
var searchresults = data.GetData(searchBox.Text);
int datanumber = searchresults.Count();
if (datanumber == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "javascript:alert('There were no records found to match your search');", true);
}
else
{
DropDownList1.Visible = true;
DropDownList1.Items.Clear();
DropDownList1.DataSource = searchresults;
DropDownList1.DataBind();
}
I agree with the not using popups, so you could always do something as simple as having a Label object on your page:
<asp:Label runat="server" id="lblResultMsg" ForeColor="Red" Visible="False" />
And then set the text dynamically (or add it as a property to the code) and set the label to be visible on postback if no results are found:
if (datanumber == 0)
{
lblResultMsg.Text = "There were no records found to match your search.";
lblResultMsg.Visible = true;
}
else
{
lblResultMsg.Text = "";
lblResultMsg.Visible = false;
// do your data binding
}
But there are quite a vast number of ways you could achieve something like this. Regarding your question about using the .Count from the Enumerable collection - there's nothing stopping you doing this as it's perfectly valid. The question is which method do you find more readable?
if you include the jquery ui dialog (http://jqueryui.com/demos/dialog/), you can simply call this to create a nice dialog box:
$('<div>message</div>').dialog({autoOpen:true,title:'Error'});
Personally I prefer to create a helper function for inserting the relevant javascript into the page, and only pass parameters to the function so that I don't need to worry about the messy details every time.
Something like :
public static void GrowlMessage(System.Web.UI.Control pageControl, string header = "", string message = "", bool sticky = false, string position = "top-right", string theme = "", bool closer = true, int life = 8)
{
string _js = "$.jGrowl('" + HttpContext.Current.Server.HtmlEncode(message) + "', { header:'" + header + "', sticky:" + sticky.ToString().ToLower() + ", position: '" + position + "', theme: '" + theme + "', closer: " + closer.ToString().ToLower() + ", life:" + life * 1000 + "});";
ScriptManager.RegisterStartupScript(pageControl, pageControl.GetType(),"Growl",_js, true);
}
The sample I have used also requires jQuery and the jGrowl library available here. And IMHO the messages are pretty. They are unobtrusive, the user does not need to click a button to make them go away, and they fade away after your specified amount of time.
But I agree with Mike, that if you don't have any records, you should just use the built in properties of a GridView (EmptyDataRowStyle and EmptyDataRowText) to display a 'no data matching your query' style message. Assuming that you're using a GridView at all, that is..
When it comes to user feedback, Impromptu is my friend. There is a nice ASP.NET implementation of Impromptu on Aaron Goldenthal's website: http://www.aarongoldenthal.com/post/2009/11/11/Using-jQuery-Impromptu-With-ASPNET.aspx
If you have decided to alert user via alert then please go ahead with light box effect..
http://www.designyourway.net/blog/resources/30-efficient-jquery-lightbox-plugins/
if you are still would like to go ahead with traditional alert then obviously its easy for you to fire it up on page load rather than attaching script to it..
')" ....>
Because if you require any change then you just need to alter the javascript alone and you dont need to build project again to test it...
Hope its useful for you..
Note: I'm using my own DLLs to render content so above coding may requires alteration because i did forget traditional asp codings.. :)