Today i added print functionality to a web page that basically changes the stylesheet for print formatting and also automatically fires the print dialogue for the user. On doing this in IE7 you get the message:
"The web page you are viewing is trying to close the window"
when running the follwing javascript added to the page on page load:
If Not ClientScript.IsStartupScriptRegistered(Me.GetType, "OnLoad") Then
ClientScript.RegisterStartupScript(Me.GetType, "OnLoad", "window.print();window.close();", True)
End If
All you need to do to counteract this is put the following javascript code in before the close:
window.open('','_self');
So the code will now look like this:
ClientScript.RegisterStartupScript(Me.GetType, "OnLoad", "window.print();window.open('','_self');window.close();", True)
Works a treat.
Wednesday, 21 November 2007
The web page you are viewing is trying to close the window
Posted by
Omen
at
10:08
15
comments
Labels: ASP.NET, IE, JAVASCRIPT
Wednesday, 14 November 2007
ASP.net DataList v Repeater
In building the news feed in the previous article i initially used a data list. It all worked fin in IE but when i loaded the page up in Firefox my articles were showing outside the DIV they were supposed to be in! Confusing.
After investigating it with the IE Developers Toolbar i discovered the Datalist was outputting my news articles (which were built using the ul li structure) as tables!
NOTE: IE Developers toolbar is a wicked tool for web developers! Check it out here: Internet Explorer Toolbar This tool lets you see the DOM. Invaluable in debugging your pages.
I simply switched from using a DataList to a repeater and job done! My HTML was now as it was supposed to be and formatted in the correct div.
Posted by
Omen
at
15:02
0
comments
Labels: ASP.NET
Paging Data From an XML file
I needed to display a news feed from an xml file. My original intentions were to use XML & XSL to tranform into html but i needed paging support.
I looked at the XMLData Source control and there isno paging support built onto this control. After a look around I came across a .NET class called PagedDataSource. This class abstracts the paging functionality that is used in data grids etc.
All you have to do is load the XML into a dataset, load the pageddatasource with the data from the dataset, set the paging on, set the page index and items per page. Voila! This can now be bound to any control that supports data binding. Wicked!
Here is some sample code binding it to a DataRepeater.
Dim ds As New DataSetds.ReadXml("Data.xml")Dim pagedData As New PagedDataSourceDim dv As New DataView(ds.Tables(0))dv.Sort = "SortDate DESC"pagedData.DataSource = dvpagedData.AllowPaging = TruepagedData.PageSize = ItemsPerPagepagedData.CurrentPageIndex = CurrentIndexxmlRepeater.DataSource = pagedDataxmlRepeater.DataBind()btnBack.Visible = Not pagedData.IsFirstPagebtnMore.Visible = Not pagedData.IsLastPage
Posted by
Omen
at
14:38
0
comments
Thursday, 8 November 2007
Changing the namespace of a Windows Workflow project
Today i modified the namespace of a workflow project. A little further down the track when it came to hosting the workflow the workflow runtime puked with the following message:
"Cannot initialize 'StateMachineWorkflowActivity' that does not define a valid 'InitialStateName' property."
The state machine workflow had the initial state set but as i has messed about the with the namespace i had a hunch what it was.
If you come across this error simply open up the workflow.xoml file with an XML editor and change the 'StateMachineWorkflowActivity x:Class' attribute to match your newly modified namespace, save and close.
Now when you build it will run fine. Hopefully VS2008 will fix this as i see it as a bug in the IDE. Changing the namespace should change the namespace in the xoml.
Posted by
Omen
at
14:17
0
comments
Labels: Workflow