【发布时间】:2013-04-30 13:53:30
【问题描述】:
我的 asp.net 按钮遇到了一个奇怪的问题。 一切都很好,我正在编写一个带有一些 ajax 面板和按钮的 webpart,当一个疯狂的错误出现时,它就快完成了。尽管我当时没有告诉我,但我所有的按钮都触发了相同的方法。
好吧,我发现这是由于一个已知问题:http://forums.asp.net/t/1567526.aspx/1
我试图删除被调用的方法以查看其他按钮是否会返回到它们分配的方法,从那时起,按钮不再触发任何事件。 不再...永远...
我放回了方法,用新代码创建了一个新的 webpart,恢复了我的站点的备份,重置了我的服务器,重新启动了 Visual Studio,最后我试图用一个全新的代码创建一个全新的 VS 解决方案.我只有一个带有一个单独的 asp 按钮的页面,但什么也没有发生......
ascx 文件:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PublicationUserControl.ascx.cs" Inherits="CripmeeWebParts.Publication.PublicationUserControl" %>
<asp:Button ID="Valider" runat="server" Text="Valider" />
ascx.cs 文件
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace CripmeeWebParts.Publication
{
public partial class PublicationUserControl : UserControl
{
protected override void OnLoad(EventArgs e)
{
EnsureChildControls();
base.OnLoad(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Valider.Click += new EventHandler(Valider_Click);
}
void Valider_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
}
我把这一切都绑起来了:
在 ascx 代码或 CreateChildControls 上附加事件,使用 onCommand 事件,将按钮放在 <form> 中,将调试器附加到 w3 进程以查看它是否通过我的所有方法。
我只是没有想法...... 感谢您的阅读,任何建议都会很有用。
【问题讨论】:
-
您上面的代码正在运行(我创建了一个新的 Web 应用程序并对其进行了测试)。错误可能来自其他地方。如果您删除 ajax 面板,您的按钮事件会触发吗?
-
不,不是。我刚刚检查了服务器是否有最近的更新,但最后一次是在问题出现之前。最近几天我应该是唯一一个在服务器上工作的人,所以我看不到任何其他人可以更改服务器状态。
-
我试过this,但它不起作用。
-
我只能测试您在此处发布的内容;到目前为止,上面的代码没有错误。有时,如果在页面生命周期上的控件之前出现错误,则不会触发控件的事件。您可能希望在页面生命周期的每个事件处设置断点,并逐行调试。