I have recently updated one of my old ASP.NET applications from .NET 2.0 to .NET 4.5 and it was one of the first applications where I attempted to use the asp:UpdatePanel
control. It is a survey application where a user can create a survey, assigned multiple question groups to the survey and multiple questions types to each question group.
When I use the page where a user can edit the survey content that contains AsyncPostBackTrigger
objects that are registered to LinkButton
asp.net controls in question type user controls registered on the page, I get the following error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred because a control with id 'ctl00$PageBody$gvSurveyQuestions$ctl02$ctl03' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
The user control is dynamically generated based on which control the user selected to be part of the group. In the OnRowCommand
event of the DataGrid
control, it determined which user control to display based on the type of question selected. Here is a snippet of code:
survey ASPX page:
//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>
Code Behind of ASPX page:
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);
}
Code behind of user control to set link button as postback trigger on the survey ASPX page:
public event EventHandler lbCreateUpdateQuestionClick;
protected void lbCreateUpdateQuestion_OnClick(object sender, EventArgs e)
{
if (this.lbCreateUpdateQuestionClick != null)
this.lbCreateUpdateQuestionClick(sender, e);
}
Why I am getting this error and what would be some good suggestions to look where to fix it?
Courtesy of This post