ASP.NET中阻止或记录服务器控件回传事件传播
来源:互联网 发布:linux 开启端口号 编辑:程序博客网 时间:2024/05/19 23:00
今天收到有一个需求:当某个用户修改记录时,不允许其他的用户修改该条记录。尽管感觉这个需求不是很合理,但是没有办法还是要把它做出来。
在研究这个需求的时候,有一个意外的发现:
在page中,可以重载他的RaisePostBackEvent方法,此方法的描述为:触发相应的服务器控件的相应的回传时间(Notifies the server control that caused the postback that it should handle an incoming postback event.)。
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
base.RaisePostBackEvent(sourceControl, eventArgument);
}
所以此方法就是触发事件的入口,那么如果想让此页中所有的回传事件都不触发,我们仅需要注释掉相应的语句即可,或者可以在事件触发前后做相应的操作。此方法放在BasePage中:
public class BasePage : System.Web.UI.Page
{
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
if(PreTriggerEvent(sourceControl,eventArgument))
{
base.RaisePostBackEvent(sourceControl, eventArgument);
}
PostTriggerEvent(sourceControl, eventArgument);
}
protected virtual bool PreTriggerEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
return true;
}
protected virtual void PostTriggerEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
}
}
如上所示PreTriggerEvent的返回值可以决定是否传播事件。
然后让相应的也继承BasePage,而不是默认的System.Web.UI.Page。在现行的页中重写PreTriggerEvent和PostTriggerEvent:
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected override bool PreTriggerEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
return true;
}
protected override void PostTriggerEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
}
}
支持设计全部完成,希望这个小的架构能够对大家有所帮助。
- ASP.NET中阻止或记录服务器控件回传事件传播
- asp.net 服务器控件LinkButton等在后台代码中设置js事件或添加css样式
- asp.net用户控件ascx中,如何在js中获取asp.net标准控件或服务器控件
- jQuery阻止事件传播
- 阻止事件传播
- ASP.NET 服务器控件事件的特点
- ASP.NET Web 服务器控件事件模型
- ASP.NET Web 服务器控件事件模型
- ASP.NET - TreeView Web 服务器控件事件
- ASP.NET 2.0 服务器控件之复合控件事件
- ASP.NET 2.0服务器控件之复合控件事件
- Asp.net控件开发学习笔记(八)----服务器控件事件
- Asp.net控件开发学习笔记(九)----服务器控件事件
- ASP.NET服务器控件【触发事件交给服务器处理】
- 阻止冒泡,阻止一个事件传播
- 阻止默认行为和阻止事件传播
- js 如何阻止事件传播
- 在asp.net服务器控件中响应客户端与服务器端事件的例子
- 创建IO时的参考特征
- jQuery.getJSON 读取数组的两种方式
- 糗大了:奥巴马竞争对手Romney大购Twitter僵尸粉被发现
- Java Oracle驱动包
- [Ubuntus手记]GIMP使用心得
- ASP.NET中阻止或记录服务器控件回传事件传播
- eclipse无法正确显示代码提示,显示No Default Proposals
- eclipse快捷键
- 字符串数组的复制(不仅仅字符串)
- 透明网关安装和配置
- 交换机
- ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法
- 在使用MyEclipse 6中不能使用 alt + / 快捷键进行快速提示。
- 算法导论-22.2-7-树的直径