【发布时间】:2013-12-09 21:02:50
【问题描述】:
我最近将我的一个旧 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 属性 引发回发事件以避免此错误。
用户控件是根据用户选择哪个控件作为组的一部分动态生成的。在DataGrid 控件的OnRowCommand 事件中,它根据所选问题的类型确定要显示哪个用户控件。这是一段sn-p代码:
调查 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);
}
为什么我会收到这个错误,有什么好的建议可以帮助我解决这个问题?
【问题讨论】:
标签: c# asp.net user-controls updatepanel asyncpostbackerror