这至少是你如何做到这一点的起点。我不确定所有的逻辑是100%,但它是开始...
protected void Page_Load(object sender, EventArgs e)
{
foreach (Control control in Controls)
{
DisableEvent(control);
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
foreach (Control control in Controls)
{
UpdateViewstate(control);
}
}
private void DisableEvent(Control current)
{
foreach (Control control in current.Controls)
{
if (control.GetType() == typeof(Button))
{
if (IsPostBack)
{
if (Session["update" + control.ID].ToString() != ViewState["update" + control.ID].ToString())
{
RemoveClickEvent((Button)control);
}
else
{
((Button)control).Click += new EventHandler(Button_Disable);
}
}
else
{
Session["update" + control.ID] = Server.UrlEncode(System.DateTime.Now.ToString());
}
}
DisableEvent(control);
}
}
private void UpdateViewstate(Control current)
{
foreach (Control control in current.Controls)
{
if (control.GetType() == typeof(Button))
{
ViewState["update" + control.ID] = Session["update" + control.ID];
}
UpdateViewstate(control);
}
}
void RemoveClickEvent(Button b) {
System.Reflection.FieldInfo f1 = typeof(Button).GetField("EventClick", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
object obj = f1.GetValue(b);
System.Reflection.PropertyInfo pi = typeof(Button).GetProperty("Events", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
System.ComponentModel.EventHandlerList list = (System.ComponentModel.EventHandlerList)pi.GetValue(b, null);
list.RemoveHandler(obj, list[obj]);
}
protected void Button_Disable(object sender, EventArgs e)
{
Button b = (Button)sender;
Session["update" + b.ID] = Server.UrlEncode(System.DateTime.Now.ToString());
}
来源
2009-09-03 10:01:01
awe
我明白...但在这个页面,我自己提供了一个刷新按钮,用户可以使用刷新内容...我想阻止按钮点击和其他事件再次被解雇。 – 2009-09-03 08:17:36
@The King--你自己的刷新按钮与内置于浏览器中的刷新按钮有什么关系? – RichardOD 2009-09-03 08:51:02
我自己的刷新按钮只是重新加载页面,并且不会再次触发最后一个控件事件。 – 2009-09-03 09:51:17