Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView linkbutton not causing external UpdatePanel to refresh

I have an asp page with a regular panel that contains a gridview. The gridview has some linkbuttons that are used to generate a pdf.

I also have an UpdatePanel inside the regular panel and below the gridview that contains a label.

When the user clicks the 'generate' linkbutton inside the gridview, I want the label to say 'report generating' or something like that.

I have been unable to get this to work at all. I can throw values into the label all day long and nothing.

Here is the code for the panel:

<asp:Panel ID="ReportsPanel" runat="server" Height="611px">
    <h2>
        Reports
    </h2>
    <asp:Label ID="ReportsNotification" runat="server"></asp:Label>
    <br />
    <asp:Label ID="Label1" runat="server" Text="Pharmacy: "></asp:Label>
    <asp:DropDownList ID="PharmaciesDropDownList" runat="server" AutoPostBack="true"
        OnSelectedIndexChanged="PharmaciesDropDownList_SelectedIndexChanged">
    </asp:DropDownList>
    <br />
    <br />
    <asp:GridView ID="ListReportsGridView" runat="server" AllowPaging="true" AllowSorting="true"
        GridLines="None" PageSize="10" CssClass="GridView" AutoGenerateColumns="false"
        EmptyDataText="No rows for selection." OnRowCommand="ListReportsGridView_RowCommand"
        OnPageIndexChanging="ListReportsGridView_PageIndexChanging"
        EnablePersistedSelection="True"
        DataKeyNames="FinDataID">
        <AlternatingRowStyle CssClass="GridViewAltRow" />
        <HeaderStyle CssClass="GridViewHeader" />
        <RowStyle CssClass="GridViewItem" />
        <PagerStyle CssClass="GridViewPager" />
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" ControlStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden"
                HeaderStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden" />
            <asp:BoundField DataField="FinDataID" HeaderText="FinDataID" ControlStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden"
                HeaderStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden" />
            <asp:BoundField DataField="PeriodStart" HeaderText="Period Start" DataFormatString="{0:dd/MM/yyyy}" />
            <asp:BoundField DataField="PeriodEnd" HeaderText="Period End" DataFormatString="{0:dd/MM/yyyy}" />
            <asp:TemplateField HeaderText="Reports Available for Download"><ItemTemplate><asp:LinkButton ID="LinkButtonViewRpt" Text='<%#Eval("FileName") %>' CommandName="ViewRpt" CommandArgument="<%# Container.DataItemIndex %>" runat="server"></asp:LinkButton></ItemTemplate></asp:TemplateField>    
            <asp:TemplateField Visible="false"><ItemTemplate><asp:LinkButton ID="LinkButtonGenerateRpt" Text='Generate' CommandName="GenerateRpt" CommandArgument="<%# Container.DataItemIndex %>" runat="server"></asp:LinkButton></ItemTemplate></asp:TemplateField>    
            <asp:TemplateField Visible="false"><ItemTemplate><asp:LinkButton ID="LinkButtonUploadRpt" Text='Upload' CommandName="UploadRpt" CommandArgument="<%# Container.DataItemIndex %>" runat="server"></asp:LinkButton></ItemTemplate></asp:TemplateField>    
        </Columns>
    </asp:GridView>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LinkButtonGenerateRpt" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
</asp:Panel>

I've tried with a button in the UpdatePanel, outside the UpdatePanel but neither of those ideas worked either. Surely this is possible!

The one thing I'm wondering, is when the 'generate' button fires and creates the pdf it is calling Response.End. I know this will end the thread and not reload the page. But I was hoping I could refresh the UpdatePanel before this happens... from what I can tell that's what UpdatePanel's are for, partial page updates.

Here is the code behind for the gridview:

protected void ListReportsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    intIndex = Convert.ToInt32(e.CommandArgument);
    if (e.CommandName == "GenerateRpt")
    {//render pdf

        //populate empty report object with row information
        objFileData = new FileData();
        objFileData.PharmacyID = Convert.ToInt32(PharmaciesDropDownList.SelectedValue);
        objFileData.FinDataID = Convert.ToInt32(ListReportsGridView.Rows[intIndex].Cells[1].Text);
        objFileData.CreateDate = Convert.ToDateTime(DateTime.Now);
        objFileData.CreatedByID = Convert.ToInt32(Session["UserID"]);
        objFileData.PeriodStart = Convert.ToDateTime(ListReportsGridView.Rows[intIndex].Cells[2].Text);

        lblMessage.Text = "Report generating...";
        //btnGenerate_Click(sender, e);
        RenderPdf();

    }

Thanks in advance!

EDIT: And I'm also receiving this error...

A control with ID 'LinkButtonGenerateRpt' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

Do I need to use the UniqueID or is scope otherwise an issue?

like image 816
s.bramblet Avatar asked Mar 23 '23 00:03

s.bramblet


1 Answers

Your updatepanel UpdateMode is conditional and you have to trigger the update yourself so when you need to update it you have to say UpdatePanel1.Update();

like image 149
Kiarash Avatar answered Apr 25 '23 01:04

Kiarash