积极答复者
silverlight App丢失

问题
-
最近在弄一个B/S系统,系统上采用extjs搭建前台,多个功能中用iframe切换,其中有且只有一个iframe中是Silverlight应用程序【是BingMap的一个】。
问题:
如果我在不同iframe中切换时,有时候我从Silverlight 的 iframe切换到其他iframe的瞬间,Silverlight应用会莫名奇妙的执行Application_Exit。这样一来,如果我以后切换回Silverlight应用,App的构造函数会App()、Application_Startup()就重新执行,Silverlight会重新加载,我原来的Silverlight各种东西就丢失了。经过测试,iframe中的html没有重新加载【通过alert测试】。所以问题应该在Silverlight上。
上述问题,,在chrome中没有遇到,在ie8中会遇到。
环境:
window7 + vs2010 sp1 + Silverlight 5 。
请教,这是什么原因?有什么方法解决?
- 已编辑 mazhlo 2012年12月5日 2:13
答案
-
你好,
根据你的描述,我做了一个测试,结果是正常的,我不知道你的切换是不是和我的一样,如果不是请你提供切换的代码
我的切换的完整代码如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function btn1() { var div2 = document.getElementById("div2"); div2.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "none"; var div1 = document.getElementById("div1"); div1.style.display = "block"; } function btn2() { var div1 = document.getElementById("div1"); div1.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "none"; var div2 = document.getElementById("div2"); div2.style.display = "block"; } function btn3() { var div2 = document.getElementById("div2"); div2.style.display = "none"; var div1 = document.getElementById("div1"); div1.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "block"; } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" id="Button1" onclick="btn1();" value="btn1" /> <input type="button" id="Button2" onclick="btn2();" value="btn2" /> <input type="button" id="Button3" onclick="btn3();" value="btn3" /> <div id="div1" style='display:none;'><span>Home</span><iframe src='WebForm1.aspx'></iframe></div> <div id="div2" style='display:block;'><span>Setting</span><iframe src='SilverlightApplication10TestPage.aspx'></iframe></div> <div id="div3" style='display:none;'><span>BingMap</span><iframe src='SilverlightApplication10TestPage.html'></iframe></div> </div> </form> </body> </html>
div1里面是一个在iframe里的普通页面,div2里面有在iframe里的silverlight程序,在IE里运行的结果如下:
这里的三个按钮,不管怎么切换,silverlight程序都不会重新加载。
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 iwpfModerator 2012年12月7日 9:59
- 已建议为答案 iwpfModerator 2012年12月11日 7:02
- 已标记为答案 iwpfModerator 2012年12月12日 7:54
全部回复
-
你好,
>>如果我在不同iframe中切换
我不清楚你是怎么切换的, 请你贴一些代码解释一下。
如果是加载页面到iframe里,这样肯定会刷新的[所有浏览器都会刷新]
<head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <a href="SilverlightApplicationDevTestPage.aspx" target="frame">1</a> <a href="SilverlightApplicationDevTestPage.html" target="frame">2</a> <a href="WebForm1.aspx" target="frame">3</a> <iframe name="frame" style="height: 400px; width: 800px"></iframe> </form> </body> </html>
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
感谢您的回复。
extjs生成的,比较多。但是类似这种了:
<html>
<body>
<div style='display:none;'><span>Home</span><iframe src='home.aspx'></iframe></div>
<div style='display:block;'><span>Setting</span><iframe src='Setting.aspx'></iframe></div>
<div style='display:none;'><span>BingMap</span><iframe src='bingmap.aspx'></iframe></div>
</body>
</html>
其中bingmap.aspx中承载了silverlight程序。切换过程就是控制div的隐藏和显示,所有不存在刷新的情况【用来切换的js在此处就不在写了】。
我在bingmap.aspx中页面加载处采用 alert 方式测试,发现bingmap.aspx确实只加载了1次;在silverlight的app()构造函数中通过MessageBox.show测试,发现出错后会重复弹出提示。
并且我还发现我切换到Silverlight后,如果我不动Silverlight里的东西【比如拖动地图】,再切换到其他功能,就不会application_exit,但是如果我切换后点Silverlight里的东西【比如拖动地图】,再切换的瞬间就Application_Exit了。
另外,chrome中整个切换流程是没有问题的哦,所有我想肯定不是在html或js上的错误。
- 已编辑 mazhlo 2012年12月6日 10:42
-
你好,
根据你的描述,我做了一个测试,结果是正常的,我不知道你的切换是不是和我的一样,如果不是请你提供切换的代码
我的切换的完整代码如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function btn1() { var div2 = document.getElementById("div2"); div2.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "none"; var div1 = document.getElementById("div1"); div1.style.display = "block"; } function btn2() { var div1 = document.getElementById("div1"); div1.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "none"; var div2 = document.getElementById("div2"); div2.style.display = "block"; } function btn3() { var div2 = document.getElementById("div2"); div2.style.display = "none"; var div1 = document.getElementById("div1"); div1.style.display = "none"; var div3 = document.getElementById("div3"); div3.style.display = "block"; } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" id="Button1" onclick="btn1();" value="btn1" /> <input type="button" id="Button2" onclick="btn2();" value="btn2" /> <input type="button" id="Button3" onclick="btn3();" value="btn3" /> <div id="div1" style='display:none;'><span>Home</span><iframe src='WebForm1.aspx'></iframe></div> <div id="div2" style='display:block;'><span>Setting</span><iframe src='SilverlightApplication10TestPage.aspx'></iframe></div> <div id="div3" style='display:none;'><span>BingMap</span><iframe src='SilverlightApplication10TestPage.html'></iframe></div> </div> </form> </body> </html>
div1里面是一个在iframe里的普通页面,div2里面有在iframe里的silverlight程序,在IE里运行的结果如下:
这里的三个按钮,不管怎么切换,silverlight程序都不会重新加载。
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 iwpfModerator 2012年12月7日 9:59
- 已建议为答案 iwpfModerator 2012年12月11日 7:02
- 已标记为答案 iwpfModerator 2012年12月12日 7:54