0

I have one UpdatePanel includes threeRepeater in my ascx like below:

<asp:UpdatePanel ID="myUpdatePanel" runat="server">
    <ContentTemplate>
        <%-- Info (Repeater 1)--%>
        <div id="info" class="tab-pane">
            <asp:Repeater ID="rptInfo" runat="server">
                <ItemTemplate>
                    <asp:LinkButton runat="server"
                        ID="lnkSaveInfo"
                        CommandName="saveInfo"
                        ClientIDMode="AutoID" />
                </ItemTemplate>
            </asp:Repeater>
        </div>

        <%-- Documents (Repeater 2)--%>
        <div id="documents" class="tab-pane">
            <asp:Repeater ID="rptDocumentDefs" runat="server">
                <ItemTemplate>

                    <table class="table table-striped table-bordered table-hover">
                        <%-- subDocuments (Repeater 3)--%>
                        <asp:Repeater ID="rptSubDocumnets" runat="server" OnItemCommand="rptSubDocumnets_ItemCommand" OnItemDataBound="rptSubDocumnets_ItemDataBound">
                            <ItemTemplate>
                                <tr class="rgRow">
                                    <td>
                                        <asp:LinkButton runat="server"
                                            ID="LnkDownLoadDocument"
                                            CommandName="downLoadDocument"
                                            ClientIDMode="AutoID">
                                        </asp:LinkButton>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </table>

                </ItemTemplate>
            </asp:Repeater>
        </div>

    </ContentTemplate>
</asp:UpdatePanel>

Code behind

public void rptSubDocumnets_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{
    ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page);
    scriptMan.RegisterPostBackControl(e.Item.FindControl("LnkDownLoadDocument") as LinkButton);
}

If I click on LnkDownLoadDocument then download file works correctly but if I click on lnkSaveInfo and after that I click on LnkDownLoadDocument, I get error like below:

Uncaught Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '�PNG

I used download method in many projects and it works properly and there isn't any errors in server side when I am debugging my codes.

None of solutions worked properly in my issue

I tried many solutions that they are similar to my problem like below, but none of them worked properly and I decided that I ask new question.

Download Item With Response

How to do AsyncPostBackTrigger for the LinkButton in the Repeater

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

It would be very helpful if someone could explain solution for this problem. Thanks in advance.

Ali Soltani
  • 9,589
  • 5
  • 30
  • 55

1 Answers1

0

Make a separate method that loops all items in the Repeater and attach the PostBack trigger there.

private void bindPosdtBackToRepeaterButtons()
{
    foreach (RepeaterItem item in rptDocumentDefs.Items)
    {
        ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page);
        scriptMan.RegisterPostBackControl(item.FindControl("LnkDownLoadDocument") as LinkButton);
    }
}

Call this method in the lnkSaveInfo handler. You can also use this instead of the DataBound event to save some lines of code. Call this method after the Repeater DataBind() is executed.

VDWWD
  • 35,079
  • 22
  • 62
  • 79