Answered by:
Sys.WebForms.PageRequestManagerServerErrorException.

Question
-
User1078534304 posted
Dear Experts,
I have two user controls in a page, and each are being activated on a dropdown control, whenever I switch to each user control, I hit this exception
Sys.WebForms.PageRequestManagerServerErrorException. Please advice, thanks.
Below is part of my code
<asp:UpdatePanel runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="ExistsBtn" runat="server" Text="Button" onclick="ExistsBtn_Click" /> <asp:Button ID="btnDeletex" runat="server" Text="Button" onclick="btnDeletex_Click" /> <asp:HiddenField ID="hidConfirmation" runat="server" /> <asp:HiddenField ID="hidConfirmDelete" runat="server"/> <asp:HiddenField ID="hidGuid" runat="server" /> <div class="form-group"> <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label"><%= "Service".Translate() %></label> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"> <asp:DropdownList ID="ddlService" runat="server" class="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlService_SelectedIndexChanged"></asp:DropdownList> </div> <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label"><%= "Order Date".Translate() %></label> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"> <asp:TextBox id="txtOrderDate" runat="server" class="form-control" disabled></asp:TextBox> </div> </div> <usc:usc1 id="usc1" runat="server"></usc:usc1> <usc:usc2 id="usc2" runat="server"></usc:usc2> <usc:ButtonBar id="btnBar" runat="server" ShowNew="true" OnSaveClick="Save_Click" OnClientSaveClick="return $('#form1').valid();" Custom1Text="Cancel" OnCustom1Click="Delete_Click"></usc:ButtonBar> </ContentTemplate> </asp:UpdatePanel>
C#:
protected void ddlService_SelectedIndexChanged(object sender, EventArgs e) { try { SwitchUSC(); } catch (Exception ex) { DisplayError(sender, ex); } }
private void SwitchUSC() { switch (base.GetServiceTypeCode(ddlService.SelectedValue.ToGuid())) { case Models.Constants.enmServiceType.usc1: usc1.Visible = true; usc2.Visible = false; break; case Models.Constants.enmServiceType.usc2: usc1.Visible = false; usc2.Visible = true; break; case Models.Constants.enmServiceType.usc3: usc1.Visible = false; usc2.Visible = false; break; default: usc1.Visible = false; usc2.Visible = false; break; } }
Thursday, September 26, 2019 8:18 AM
Answers
-
User1078534304 posted
Hi Yongqing Yu,
This has been resolved. Each of the usercontrol has a dropdown that are being re-bind whenever a postback occurs.
this is the full error description when I tried to inspect from chrome:
Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Page that use the usercontrol: protected void ddlService_SelectedIndexChanged(object sender, EventArgs e) { try { ... ShowSelected(); } catch (Exception ex) { ... } } protected void ShowSelected() { switch(ddlService.SelectedValue) { case "A": Usc1.Visible = true; Usc2.Visible = false; Usc1.Order = new Order(); ... break; default: break; } } Usercontrol CS: public Usc1 Order { get { return new Usc1 { ... }; } set { ... BindControls() } } protected void BindControls() { AnotherClass.BindControl(Dropdown1, new MyModel().List(myparam)); } public static class AnotherClass { public static void BindControl(DropdownList ddl, List<mytype> list) { ddl.DataTextField = "MyField"; ddl.DataValueField = "MyValueField"; ddl.DataSource = list; ddl.ToolTip = "(Select)"; ddl.DataBind(); } }
not really sure if it caused by the jquery (searchable plugin for dropdown list), because the ddl.ToolTip becomes another item in the original list when re-binding, after removing the line the exception did not hit anymore.
Thanks and best regards,
Nusij
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 2, 2019 2:50 AM
All replies
-
User665608656 posted
Hi Nusij,
Sys.WebForms.PageRequestManagerServerErrorException.For this error, you can try to add the following code after the script manager declaration:
<script type="text/javascript" language="javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); function EndRequestHandler(sender, args){ if (args.get_error() != undefined){ args.set_errorHandled(true); } } </script>
Best Regards,
YongQing.
Thursday, September 26, 2019 9:52 AM -
User1078534304 posted
Hi Yongqing Yu,
Thank you, I added the codes but I still hit the same error.
Thanks and best regards,
Nusij
Thursday, September 26, 2019 10:08 AM -
User665608656 posted
Hi Nusij,
If it cannot solve your issue, you can try add trigger in your updatepanel:
<asp:UpdatePanel runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="ExistsBtn" runat="server" Text="Button" onclick="ExistsBtn_Click" /> <asp:Button ID="btnDeletex" runat="server" Text="Button" onclick="btnDeletex_Click" /> <asp:HiddenField ID="hidConfirmation" runat="server" /> <asp:HiddenField ID="hidConfirmDelete" runat="server"/> <asp:HiddenField ID="hidGuid" runat="server" /> <div class="form-group"> <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label"><%= "Service".Translate() %></label> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"> <asp:DropdownList ID="ddlService" runat="server" class="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlService_SelectedIndexChanged"></asp:DropdownList> </div> <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 control-label"><%= "Order Date".Translate() %></label> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"> <asp:TextBox id="txtOrderDate" runat="server" class="form-control" disabled></asp:TextBox> </div> </div> <usc:usc1 id="usc1" runat="server"></usc:usc1> <usc:usc2 id="usc2" runat="server"></usc:usc2> <usc:ButtonBar id="btnBar" runat="server" ShowNew="true" OnSaveClick="Save_Click" OnClientSaveClick="return $('#form1').valid();" Custom1Text="Cancel" OnCustom1Click="Delete_Click"></usc:ButtonBar> </ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="ddlService" />
</Triggers> </asp:UpdatePanel>Best Regards,
YongQing.
Friday, September 27, 2019 3:11 AM -
User1078534304 posted
Hi Yongqing Yu,
Appreciate much your advices. I also tried to put triggers in the update panel but still hitting the same exceptions.
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="panel"> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlService" EventName="SelectedIndexChanged"/> </Triggers> <ContentTemplate> ... </ContentTemplate> </asp:UpdatePanel>
By the way inside each user control they have a binding procedure for dropdownlists, that is to populate selections from the database,
when I tried to comment the binding procedure from each user control (code page) it works to show/hide without the error but the dropdownlists are empty.
Thanks and best regards,
Nusij
Friday, September 27, 2019 5:21 AM -
User665608656 posted
Hi Nusij,
According to your description, I tested your code and everything works well.
I hope you can provide all the code for us to test, which will help us solve your issue more easily.
Best Regards,
YongQing.
Friday, September 27, 2019 9:48 AM -
User1078534304 posted
Hi Yongqing Yu,
This has been resolved. Each of the usercontrol has a dropdown that are being re-bind whenever a postback occurs.
this is the full error description when I tried to inspect from chrome:
Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Page that use the usercontrol: protected void ddlService_SelectedIndexChanged(object sender, EventArgs e) { try { ... ShowSelected(); } catch (Exception ex) { ... } } protected void ShowSelected() { switch(ddlService.SelectedValue) { case "A": Usc1.Visible = true; Usc2.Visible = false; Usc1.Order = new Order(); ... break; default: break; } } Usercontrol CS: public Usc1 Order { get { return new Usc1 { ... }; } set { ... BindControls() } } protected void BindControls() { AnotherClass.BindControl(Dropdown1, new MyModel().List(myparam)); } public static class AnotherClass { public static void BindControl(DropdownList ddl, List<mytype> list) { ddl.DataTextField = "MyField"; ddl.DataValueField = "MyValueField"; ddl.DataSource = list; ddl.ToolTip = "(Select)"; ddl.DataBind(); } }
not really sure if it caused by the jquery (searchable plugin for dropdown list), because the ddl.ToolTip becomes another item in the original list when re-binding, after removing the line the exception did not hit anymore.
Thanks and best regards,
Nusij
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 2, 2019 2:50 AM