我需要从 HttpModule 永久或不时更新 ASP.NET 页面。
下面是我们要更新的页面的 IUpdatablePage 接口代码:
interface IUpdatablePage
{
void Update( string value );
}
这是HttpModule的代码,我想,可以是:
void IHttpModule.Init( HttpApplication application )
{
application.PreRequestHandlerExecute += new EventHandler( application_PreRequestHandlerExecute );
}
void application_PreRequestHandlerExecute( object sender, EventArgs e )
{
this._Page = ( Page )HttpContext.Current.Handler;
}
void HttpModuleProcessing()
{
//... doing smth
IUpdatablePage page = this._Page as IUpdatablePage;
page.Update( currentVaue );
//... continue doing smth
}
在这里,我们:
- 将当前请求页面保存在 _Page 中,
- 在 HttpModule 中处理时访问 IUpdatablePage 接口
- 调用传递一些 currentValue 的更新函数。
现在页面获取更新函数中的值。
public partial class MyPage: System.Web.Page, IUpdatablePage
{
void IUpdatablePage.Update( string value )
{
// Here we need to update the page with new value
Label1.Text = value;
}
}
问题是如何将此值传输到 webform 控件以便它们立即在浏览器中显示它?
我想刷新页面的任何方式:使用 UpdatePanel、Timer、iframe 块、javascript 等。
注意,来自页面的请求在刷新时正在 HttpModule 中处理。请帮助提供代码示例(我是网络初学者)。