2

我最近将我的一个旧 ASP.NET 应用程序从 .NET 2.0 更新到 .NET 4.5,它是我尝试使用该asp:UpdatePanel控件的首批应用程序之一。这是一个调查应用程序,用户可以在其中创建调查,将多个问题组分配给调查,并将多个问题类型分配给每个问题组。

当我使用用户可以编辑包含AsyncPostBackTrigger已注册到LinkButtonasp.net 控件的对象的调查内容的页面时,在页面上注册的问题类型用户控件,我收到以下错误:

错误:Sys.WebForms.PageRequestManagerServerErrorException:发生错误,因为无法找到具有 id 'ctl00$PageBody$gvSurveyQuestions$ctl02$ctl03' 的控件,或者在回发后将不同的控件分配给相同的 ID。如果未分配 ID,请显式设置引发回发事件的控件的 ID 属性以避免此错误。

用户控件是基于用户选择哪个控件作为组的一部分而动态生成的。如果OnRowCommandDataGrid控件,它会根据所选问题的类型确定要显示哪个用户控件。这是一段代码:

调查 ASPX 页面:

//grid control to allow user to select the question to edit
<asp:GridView ID="gvSurveyQuestions" runat="server" AutoGenerateColumns="false" 
    OnRowCommand="gvSurveyQuestions_OnRowCommand" 
    OnRowEditing="gvSurveyQuestions_OnRowEditing" 
    OnRowDeleting="gvSurveyQuestions_OnRowDeleting" 
    CssClass="com_grid"
    Width="100%" 
    CellPadding="3" 
    CellSpacing="0"
>
    <asp:CommandField ButtonType="Link" ShowEditButton="True" ShowDeleteButton="True" 
        ItemStyle-HorizontalAlign="Center" />
</asp:GridView>
<asp:PlaceHolder ID="phEditExcellentPoor" runat="server" Visible="false">
    <tr>
        <td width="100%">
            <uc:ExcellentPoor Id="ucEditExcellentPoor" runat="server" EditMode="Edit" />
        </td>
    </tr>
</asp:PlaceHolder>

ASPX 页面背后的代码:

private readonly string m_CreateUpdateQuestionControlName = "lbCreateUpdateQuestion";
private readonly string m_CreateUpdateQuestionText_Edit = "Update Question";

protected void Page_Init(object sender, EventArgs e)
{
    //here is the code to set the async postback trigger
    AsyncPostBackTrigger apExcellentPoorEdit = new AsyncPostBackTrigger();
    apExcellentPoorEdit.ControlID = ucEditExcellentPoor.FindControl(this.m_CreateUpdateQuestionControlName).UniqueID;
    upSurveyQuestions.Triggers.Add(apExcellentPoorEdit);
}

用户控件后面的代码将链接按钮设置为调查 ASPX 页面上的回发触发器:

public event EventHandler lbCreateUpdateQuestionClick;

protected void lbCreateUpdateQuestion_OnClick(object sender, EventArgs e)
{
    if (this.lbCreateUpdateQuestionClick != null)
        this.lbCreateUpdateQuestionClick(sender, e);
}

为什么我会收到此错误,有什么好的建议可以查看在哪里修复它?

4

2 回答 2

0

我能够通过将编辑和删除链接替换为并将编辑从编辑重命名asp:CommandField为Edt并将删除命名Del来解决我的问题asp:ButtonFieldCommandName

这篇文章帮助最终解决了这个问题

于 2013-12-09T21:50:15.997 回答
0

切换到 .Net Framework 4.0 时,似乎具有多个 CommandField 的 Gridview 不起作用。我猜这是因为不能给gridview中的命令字段一个id,所以在这种情况下,编译器在内部为第一个命令字段分配一个控件id,当它遇到第二个时,它再次分配相同的控件id。因此,在回发期间,当我尝试重新加载 gridview 说编辑一行时,它遇到多个具有相同 ID 的控件并引发此服务器错误。

我已经删除了命令字段,而是用 TemplateField 中的 Imagebutton 替换它们,这解决了我的问题。:)

这篇文章提供

于 2013-12-09T21:09:01.653 回答