got net?

Kevin Hazzard's Brain Spigot

About the author

Welcome to Kevin Hazzard's blog.
E-mail me Send mail

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Strange Behavior for Silverlight's HtmlPage.Window.Navigate Method

I found some odd behavior today with respect to the way that Silverlight's HtmlPage.Window.Navigate method works. If a page is cacheable by the client, calling HtmlPage.Window.Navigate will always choose to load the cached version of the page. With IE7, it does this without attempting a cache update check. Normally, IE7 will emit a cache update check for cached content, expecting an HTTP 304 response code, meaning that the cached version is up-to-date. However, when HtmlPage.Window.Navigate references a cached resource, it honors the cached content without checking for an update. This is how Firefox normally behaves and it threw me for a loop as a result. Check out the following code.

// this one will used a cached version always
HtmlPage.Window.Navigate(new Uri("http://server/targetpage.aspx"));
// this one will ignore the cache
HtmlPage.Window.Eval("window.location.href='http://server/targetpage.aspx'");

In that code, the first method call will cause the browser to use a cached page. This is true even if the cache-control was set to private, which is the default. It also does not check for a cache update as IE7 normally does. The second call injects JavaScript into the hosting page for execution. That one seems to force the browser to ignore the cache where the target page was received with the private cache-control policy. I don't know if this is a bug but I know it's not documented that way. I should mention that this happens on Silverlight 2 Beta 1.


Categories: C# | Debugging | Silverlight
Posted by kevin on Monday, April 21, 2008 2:41 PM
Permalink | Comments (6) | Post RSSRSS comment feed

Comments

Sridhar United States

Tuesday, May 20, 2008 8:20 AM

Sridhar


i am using

HtmlPage.Window.Navigate(new Uri("http://server/targetpage.aspx"),"__blank");

but, i want to disable the properties of the browser. like..,height=470, width=460,status= no, resizable= no,left=45,top=45,scrollbars=no, toolbar=no,menubar=no ".

How do i do


W. Kevin Hazzard United States

Wednesday, May 21, 2008 7:10 AM

W. Kevin Hazzard

Use something like this from Silverlight:

HtmlPage.Window.Eval("window.open('Sample.htm',null,'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no');");

to set the properties of the newly opened browser window.

Bindiya United States

Tuesday, July 22, 2008 2:09 PM

Bindiya

Hey Kevin, I used the Eval method to open a new browser window but now i need to manipulate the javascript functions in the new browser and some how there has been no success. You think you can help me with that?

I was to pass in an object from the current page to the newly opened page, so I thought I could do something like

HtmlPage.Window.Eval("window.open('Test.aspx'), _blank");
HtmlPage.Window.Eval("window.document.getElementById('data').setValue(' " + dataString + "');");

Kevin Hazzard, MVP MCSD.NET United States

Wednesday, July 23, 2008 9:41 AM

Kevin Hazzard, MVP MCSD.NET

Sorry I haven't responded sooner, Bindiya. You are trying to manipulate the HTML DOM in a new _blank window that you've opened? You can do that but your Eval statement will have to be a multistatement script I think. I haven't tested this but I think something like this might work.

HtmlPage.Window.Eval("newwin = window.open('Test.aspx'); newwin.document.getElementById('data').setValue(' " + dataString + "');, _blank");

Try it and let me know, OK?

Bobby United States

Wednesday, April 01, 2009 3:40 PM

Bobby

nice description, was looking into a problem with our Silverlight app and googled my diagnosis to see if this was documented anywhere, thanks for the post!

geeks.ms

Sunday, June 07, 2009 1:41 PM

pingback

Pingback from geeks.ms

Navegando desde una página maestra mediante el control TreeView de Silverlight - El aprendiz de brujo

Comments are closed