diogo
diogo

Reputation: 771

Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument

On SharePoint, can't show/hide a table-row inside an update-panel through an event generated by a web control external do the update-panel more than once, i.e., it functions only on the first ddl item selection (although it functions perfectly outside the SharePoint context).

The error thrown:

SCRIPT5022: Sys.WebForms.PageRequestManagerServerErrorException: 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.

The aspx file:

<asp:TableRow runat="server" ID="tbr1">
    <asp:TableCell ID="tbc" runat="server" CssClass="ms-formbody">
        <asp:DropDownList ID="ddl" runat="server" EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged" />
    </asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="tbr2">
    <asp:TableCell>
        <asp:UpdatePanel ID="udp" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:Table ID="tb" runat="server">
                    <asp:TableRow runat="server" ID="tbr21">
                    <%-- content --%>
                    </asp:TableRow>
                </asp:Table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </asp:TableCell>
</asp:TableRow>

The aspx.cs file:

protected void ddl_SelectedIndexChanged(object sender, EventArgs e){
    if (ddl.SelectedItem.Text == "value1"){
        tb.Visible = true;
        // instruction here
    } else {
        tbdadospessoais.Visible = false;
        // instruction here
    }
}

Upvotes: 0

Views: 764

Answers (1)

diogo
diogo

Reputation: 771

Performed a conditional update:

The aspx file:

<asp:TableRow runat="server" ID="tbr1">
    <asp:TableCell ID="tbc" runat="server" CssClass="ms-formbody">
        <asp:DropDownList ID="ddl" runat="server" EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged" />
    </asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="tbr2">
    <asp:TableCell>
        <asp:UpdatePanel ID="udp" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:Table ID="tb" runat="server">
                    <asp:TableRow runat="server" ID="tbr21">
                    <%-- content --%>
                    </asp:TableRow>
                </asp:Table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:TableCell>
</asp:TableRow>

The aspx.cs file:

protected void ddl_SelectedIndexChanged(object sender, EventArgs e){
    if (ddl.SelectedItem.Text == "value1"){
        tb.Visible = true;
        // instruction here
        upd.update();
    } else {
        tbdadospessoais.Visible = false;
        // instruction here
        upd.update();
    }
}

Upvotes: 1

Related Questions