首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

SqlDependency如何刷新页面

2013-01-23 
SqlDependency怎么刷新页面?在OnChangeEventHandler中,我发现页面中的Respones对象没有了,也做不了跳转了,

SqlDependency怎么刷新页面?
在OnChangeEventHandler中,我发现页面中的Respones对象没有了,也做不了跳转了,注册脚本也不行,请问怎么办?
[解决办法]
参考msdn


AutomationFocusChangedEventHandler focusHandler = null;

/// <summary>
/// Create an event handler and register it.
/// </summary>
public void SubscribeToFocusChange()
{
    focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange);
    Automation.AddAutomationFocusChangedEventHandler(focusHandler);
}

/// <summary>
/// Handle the event.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e)
{
    // TODO Add event handling code.
    // The arguments tell you which elements have lost and received focus.
}

/// <summary>
/// Cancel subscription to the event.
/// </summary>
public void UnsubscribeFocusChange()
{
    if (focusHandler != null)
    {
        Automation.RemoveAutomationFocusChangedEventHandler(focusHandler);
    }
}

[解决办法]
哦 搜索一下之前的帖子 有个可以刷新的方法。 
[解决办法]
数据库的改变是随时可能发生的,这时候可能并没有人访问页面,那你要刷新哪个页面呢?

如果你确定SqlDependency是在某次访问页面的过程中创建的(并且访问结束前就注销了OnChange事件),那可以用HttpContext.Current.Response来获取当前的页面输出。
不过要小心HttpContext.Current可能是null,代表页面访问已经结束了(不可能老让浏览的用户等着)。
[解决办法]

引用:
我想到了利用脚本去访问session,不知道这个性能怎么样

性能没问题,关键是session保存的数据不要太大
[解决办法]
引用:
引用:引用:我想到了利用脚本去访问session,不知道这个性能怎么样
性能没问题,关键是session保存的数据不要太大
我是轮时查询session的

数据不太大就没问题呀

热点排行