aspx利用cookie值来停止silverlight中的计时器

一.silverlight与silverlight中可以利用委托(delegate)来刷新frame.Refresh()

1.在子类中定义委托捕捉关闭事件按钮

 1         public delegate void onCloseClick(object sender, RoutedEventArgs e);

 2         public onCloseClick onclose;

 3         private void CancelButton_Click(object sender, RoutedEventArgs e)

 4         {

 5             if (onclose != null)

 6             {

 7                 onclose(sender, e);

 8             }

 9             this.Visibility = Visibility.Collapsed;

10         }

2.在frame所在的页面中利用委托来调用frame.refresh()方法

 List<Button> listButton = ShowOpenPanelConfig(tb);

                Child_YJCBS yjcb = new Child_YJCBS();

                OPPanel op = EasySL.Controls.Window.ShowOpPanel("一键出表", yjcb, this.floatePanel, txtMsgInfo);

                op.onclose += (s, e) => { ContentFrame.Refresh(); };

                yjcb.onclose += (s, e) =>

                {

                    op.Visibility = Visibility.Collapsed; ContentFrame.Refresh();

                };
View Code

二、利用aspx中的cookie来控制sl中的定时器
1.在frame所在的页面中定义计时器

 1  private void TimeInitData()

 2         {

 3             if (myDispatcherTimer != null)

 4                 myDispatcherTimer.Stop();

 5             //创建计时器      

 6             myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();

 7             //创建间隔时间     

 8             myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 5);

 9             //创建到达间隔时间后需执行的函数    

10             myDispatcherTimer.Tick += (ss, ee) =>

11             {

12                 this.ContentFrame.Refresh();

13                 String[] cookies = HtmlPage.Document.Cookies.Split(';');

14                 foreach (String cookie in cookies)

15                 {

16                     String[] keyValues = cookie.Split('=');

17                     {

18                         if (keyValues[0].Trim() == "FirCookieKey")

19                         {

20                             myDispatcherTimer.Stop();

21                         }

22                     }

23                 }

24 

25             };

26             myDispatcherTimer.Start();

27         }

2.在aspx页面中创建cookie并设置cookie的过期时间

 1  if (isSuccess)

 2             {

 3                 Response.Cookies.Clear();

 4                 HttpCookie MyCookie = new HttpCookie("FirCookieKey");

 5                 MyCookie.Value = "NewCookieValue";

 6                 MyCookie.Expires =DateTime.Now.Add(TimeSpan.FromMinutes(0.2));

 7                 HttpContext.Current.Response.Cookies.Add(MyCookie);

 8                 Server.Transfer("PreviewReport.aspx");

 9                 //Page.Response.Write("<script language=javascript>alert(\" 插入成功!\");</script>");

10             }

注意:以上设置的cookie过期时间为12秒,而sl是已5秒中的加载一次,

 

你可能感兴趣的:(silverlight)