?
Solved

Pdf Viewer refreshes during page index change of gridview on asp.net page

Posted on 2015-02-09
4
Medium Priority
?
188 Views
Last Modified: 2015-02-16
I have a gridview on an asp.net page with two link buttons - one for viewing a pdf and one for downloading.   When  you click View a pdf viewer is displayed in a literal control.  This works fine.  But I have paging enabled for my gridview and when I click the paging links the pdf display refreshes, meaning it will reload the last pdf viewed.  I'm guessing it has something to do with postback but can't figure out a solution.
<div id="wpaLinks" style="height: 118px;">
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">                         
                    <ContentTemplate>
                        <asp:GridView ID="gvWPAs" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="3" CssClass="Grid" AlternatingRowStyle-CssClass="alt"  
                            PagerStyle-CssClass="pgr" EmptyDataText="No Records Found" OnPageIndexChanging="gvWPAs_PageIndexChanging">  <%--OnRowDataBound="gvWPAs_RowDataBound"--%>
                                <AlternatingRowStyle CssClass="alt" />
                                <Columns>
                                    <asp:BoundField DataField="fileDescription" HeaderText="File Description" />
                                    <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkView" runat="server" Text="View" OnClick="View" CommandArgument='<%# Eval("relPath") %>'></asp:LinkButton>
                                            <asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("relPath") %>' runat="server" OnClick="DownloadFile"></asp:LinkButton>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                </Columns>
                            <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" PageButtonCount="4" />
                            <PagerStyle CssClass="pgr" />
                        </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
                </div>

           
                <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                    <ContentTemplate>
                        <asp:Literal ID="ltEmbed" runat="server" />
                    </ContentTemplate>
                </asp:UpdatePanel>
           

Open in new window


code-behind...
protected void gvWPAs_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvWPAs.PageIndex = e.NewPageIndex;
        var ctyID = CountyList.SelectedValue;
        var twnID = TwnList.SelectedValue;
        var rngID = RngList.SelectedValue;

        if (ctyID != "0" & twnID == "0" & rngID == "0") // County only
        {
            dsGetCtyWPAs.SelectParameters["ctyID"].DefaultValue = ctyID;
            DataView dvCtyWpa = (DataView)dsGetCtyWPAs.Select(DataSourceSelectArguments.Empty);
            //DataTable dtCtyWpa = dvCtyWpa.ToTable();
            gvWPAs.DataSource = dvCtyWpa;
            gvWPAs.DataBind();
            this.RegisterPostBackControl();
        }
        
    }


    protected void View(object sender, EventArgs e)
    {
        string pdfIdentifier = (sender as LinkButton).CommandArgument;
        string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"650px\" height=\"850px\">";
        embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>";
        embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
        embed += "</object>";
        ltEmbed.Text = string.Format(embed, ResolveUrl("~/PdfHandler.ashx?pdfPath="), "WpaFiles/" + pdfIdentifier);
        
    }



    protected void DownloadFile(object sender, EventArgs e)
    {
        string filePath = (sender as LinkButton).CommandArgument;        
        string fileName = Path.GetFileName(filePath);        
        Downloader.Download(fileName, "WpaFiles/" + filePath);
    }

Open in new window

0
Comment
Question by:Nate_LR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40600553
use IsPostBack Property...
0
 

Author Comment

by:Nate_LR
ID: 40600788
Ok, like this?....
protected void gvWPAs_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (!Page.IsPostBack)
        {
            gvWPAs.PageIndex = e.NewPageIndex;
            var ctyID = CountyList.SelectedValue;
            var twnID = TwnList.SelectedValue;
            var rngID = RngList.SelectedValue;

            if (ctyID != "0" & twnID == "0" & rngID == "0") // County only
            {
                dsGetCtyWPAs.SelectParameters["ctyID"].DefaultValue = ctyID;
                DataView dvCtyWpa = (DataView)dsGetCtyWPAs.Select(DataSourceSelectArguments.Empty);
                gvWPAs.DataSource = dvCtyWpa;
                gvWPAs.DataBind();
                this.RegisterPostBackControl();

            }
            else if (ctyID != "0" & twnID != "0" & rngID != "0") //County, township, and range
            {
                dsGetCTRWPAs.SelectParameters["ctyID"].DefaultValue = ctyID;
                dsGetCTRWPAs.SelectParameters["twnID"].DefaultValue = twnID;
                dsGetCTRWPAs.SelectParameters["rngID"].DefaultValue = rngID;
                DataView dvCTRWpa = (DataView)dsGetCTRWPAs.Select(DataSourceSelectArguments.Empty);
                gvWPAs.DataSource = dvCTRWpa;
                gvWPAs.DataBind();
                this.RegisterPostBackControl();

            }
            else if (ctyID == "0" & twnID != "0" & rngID != "0") // Township and Range
            {
                dsGetTRWPAs.SelectParameters["twnID"].DefaultValue = twnID;
                dsGetTRWPAs.SelectParameters["rngID"].DefaultValue = rngID;
                DataView dvTRWpa = (DataView)dsGetTRWPAs.Select(DataSourceSelectArguments.Empty);
                gvWPAs.DataSource = dvTRWpa;
                gvWPAs.DataBind();
                this.RegisterPostBackControl();
            }
        }
    }


    protected void View(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string pdfIdentifier = (sender as LinkButton).CommandArgument;
            string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"650px\" height=\"850px\">";
            embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>";
            embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
            embed += "</object>";
            ltEmbed.Text = string.Format(embed, ResolveUrl("~/PdfHandler.ashx?pdfPath="), "WpaFiles/" + pdfIdentifier);
            this.RegisterPostBackControl();
        }
    }

Open in new window

They don't work if I do that, so is that how you mean?
0
 

Accepted Solution

by:
Nate_LR earned 0 total points
ID: 40604584
I set the UpdateMode to Conditional on UpdatePanel3
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">                     
                <ContentTemplate>
                    <asp:Literal ID="ltEmbed" runat="server" />
                </ContentTemplate>
            </asp:UpdatePanel>

Open in new window

Then added UpdatePanel3.Update() to....
protected void View(object sender, EventArgs e)
{
string pdfIdentifier = (sender as LinkButton).CommandArgument;
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"650px\" height=\"850px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
ltEmbed.Text = string.Format(embed, ResolveUrl("~/PdfHandler.ashx?pdfPath="), "WpaFiles/" + pdfIdentifier);
UpdatePanel3.Update();
}

Open in new window

0
 

Author Closing Comment

by:Nate_LR
ID: 40611868
I figured it out with no help from "Experts"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

*Adobe Acrobat 9 was used for this article. Particular steps may vary depending on software versions. 1. Create a framework of your form in Word, leaving space where you’d ultimately like the Adobe fields to appear.  (Note: I use the blank lines …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question