日期:2014-05-17  浏览次数:20525 次

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的

数据不太大就没问题呀