473,794 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening PDF in new window on click of linkbutton in datagrid

Hi,

I need to open PDF document in new window when i click on linkbutton
in datagrid.For that i have written code as below:

But the problem with this code is that it opens the new window ,but not
loading the pdf.Please let me know how can i solve this issue.

private void grdTest_ItemCom mand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
if(e.CommandNam e=="View")
{
LinkButton btn = e.Item.FindCont rol("linkView") as LinkButton;

GetPDF();
btn.Attributes. Add("Onclick"," window.open('Te stData.aspx');" +
"return false;");
}
}
Here is the GetPDF function:

public void GetPDF()
{

FileStream fs;
string fname;
fname = MapPath("../") + "via project/documents/Mass_title.pdf" ;
fs = File.Open(fname , FileMode.Open);
byte[] data = new byte[fs.Length];
int i=(int)fs.Lengt h;
fs.Read(data, 0, i);
fs.Close();
Response.Clear( );
Response.Charse t = "";
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Disposition",
"inline;filenam e=pdfTest.pdf") ;
Response.Binary Write(data);
Response.End();

}
Thanks,
Vishnu

Nov 16 '06 #1
1 6100
Hi,

You need to place the function GetPDF() in your TestData.aspx.v b 's
PageLoad.

vt

se****@gmail.co m wrote:
Hi,

I need to open PDF document in new window when i click on linkbutton
in datagrid.For that i have written code as below:

But the problem with this code is that it opens the new window ,but not
loading the pdf.Please let me know how can i solve this issue.

private void grdTest_ItemCom mand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
if(e.CommandNam e=="View")
{
LinkButton btn = e.Item.FindCont rol("linkView") as LinkButton;

GetPDF();
btn.Attributes. Add("Onclick"," window.open('Te stData.aspx');" +
"return false;");
}
}
Here is the GetPDF function:

public void GetPDF()
{

FileStream fs;
string fname;
fname = MapPath("../") + "via project/documents/Mass_title.pdf" ;
fs = File.Open(fname , FileMode.Open);
byte[] data = new byte[fs.Length];
int i=(int)fs.Lengt h;
fs.Read(data, 0, i);
fs.Close();
Response.Clear( );
Response.Charse t = "";
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Disposition",
"inline;filenam e=pdfTest.pdf") ;
Response.Binary Write(data);
Response.End();

}
Thanks,
Vishnu
Nov 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
435
by: ChrisB | last post by:
I'm attempting to open a new window from a LinkButton in a DataGrid. I can set a session variable in the ItemCommand event for the LinkButton like so: // this is used to handle the ItemCommand event private void itmCmd(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string itemGFNo = ""; if (e.CommandName == "EditTask")
3
2127
by: Raymond Lewallen | last post by:
I have a modal dialog displaying a datagrid control. Click on the column header to sort the datagrid opens a new window with the following in the location: javascript:__doPostBack('dgDataGrid$_ctl1$_ctl1','') instead of actually posting back to the modal dialog and sorting the datagrid. ItemDataBound, ItemCommand events both work fine, only the SortCommand is producing this unwanted behavior.
2
5595
by: Dave | last post by:
Hi, I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes a few seconds. The js function simply sets the css style to display. <asp:TemplateColumn> <ItemTemplate> <asp:LinkButton Runat="server" CommandName="Select" ID="lbtnCompanyName"> <%# DataBinder.Eval(Container.DataItem, "CompanyName")%>...
1
1469
by: George Durzi | last post by:
I have a DataGrid which contains 1 visible column which is a LinkButton: <Columns> <asp:BoundColumn DataField="ProductId" Visible="False"></asp:BoundColumn> <asp:BoundColumn DataField="DownloadURL" Visible="False"></asp:BoundColumn> <asp:TemplateColumn> <ItemTemplate> <asp:LinkButton ID="lnkArticle" Runat="server"
6
2438
by: SkeanDu | last post by:
Ok, here is my problem. I have an aspx page that displays a databound datagrid and in one of the datagrid column headers I have an image that when clicked opens up a modal web dialog (another aspx page). >From this dialog I want the users to be able to select a filter item from a databound combobox and click on the apply button on the web dialog that will then disappear and the filtered data will be displayed on my datagrid.
1
2026
by: Jennyfer J Barco | last post by:
Hello I have a datagrid and a linkbuttom in the datagrid that says Picture, every time I click on the link "Picture" my program opens a popup window showing a picture of the item the selected and information about the item. On the html of the datagrid I have the following: OnItemCommand="Grid_CartCommand" OnItemCreated="DataGrid_ItemCreated". My VB functions are the following: Sub DataGrid_ItemCreated(ByVal Sender As Object, ByVal e As...
1
2325
by: geronimi | last post by:
I want to create a linkbutton in a cell because not every row needs one (so I can't setup a linkbuttoncolumn instead of a boundcolumn.) First, i create a linkbutton in the datagrid_ItemDataBound : Dim linkButton As New LinkButton linkButton.Text = name linkButton.CommandName = "PassSelectedClient" linkButton.CommandArgument = id I add it to the controls
2
7213
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in ASPX page <asp:DataGrid id="MyGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" runat="server" EnableViewState="True"> <Columns>
1
3393
by: settyv | last post by:
Hi, I need to open PDF document in new window when i click on linkbutton in datagrid.For that i have written code as below: But the problem with this code is that it opens the new window ,but not
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.