我最近将我的一个旧 ASP.NET 应用程序从 .NET 2.0 更新到 .NET 4.5,它是我尝试使用该asp:UpdatePanel
控件的首批应用程序之一。这是一个调查应用程序,用户可以在其中创建调查,将多个问题组分配给调查,并将多个问题类型分配给每个问题组。
当我使用用户可以编辑包含AsyncPostBackTrigger
已注册到LinkButton
asp.net 控件的对象的调查内容的页面时,在页面上注册的问题类型用户控件,我收到以下错误:
错误:Sys.WebForms.PageRequestManagerServerErrorException:发生错误,因为无法找到具有 id 'ctl00$PageBody$gvSurveyQuestions$ctl02$ctl03' 的控件,或者在回发后将不同的控件分配给相同的 ID。如果未分配 ID,请显式设置引发回发事件的控件的 ID 属性以避免此错误。
用户控件是基于用户选择哪个控件作为组的一部分而动态生成的。如果OnRowCommand
是DataGrid
控件,它会根据所选问题的类型确定要显示哪个用户控件。这是一段代码:
调查 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);
}
为什么我会收到此错误,有什么好的建议可以查看在哪里修复它?