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

by kevin 4/21/2008 2:41:00 PM

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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C# | Debugging | Silverlight

Related posts

Comments

5/20/2008 8:20:42 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


Sridhar us

5/21/2008 7:10:47 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.

W. Kevin Hazzard us

7/22/2008 2:09:26 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 + "');");

Bindiya us

7/23/2008 9:41:05 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?

Kevin Hazzard, MVP MCSD.NET us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/23/2008 8:04:39 PM

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen


Kevin's on Twitter / FriendFeed

W. Kevin Hazzard Welcome to Kevin Hazzard's Blog. Kevin is a Software Architect, Professor and Microsoft MVP specializing in C#, WCF, Silverlight and IronPython.

View Kevin Hazzard's profile on LinkedIn
Microsoft MVP Award Join me at CodeStock

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

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 2008

Sign in