473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Opening pdfstream in new window in asp.net-Help me

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_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="View")
{
LinkButton btn =
e.Item.FindControl("linkView") as LinkButton;

Label lbl=e.Item.FindControl("lblText") as Label ;
sp.DmsID=lbl.Text;
GetPDFDoc(sp);
btn.Attributes.Add("Onclick","window.open('TestDat a.aspx');" +
"return false;");
}
}
Here is the GetPDF function:
public void GetPDFDoc(SearchParams sp)
{
//Tentative tr=new Tentative();
Minute min=new Minute();

MemoryStream pdfStream = new MemoryStream();

pdfStream = min.GetMinuteOrderPdf(sp);

Response.Clear();
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader( "content-length", System.Convert.ToString(
pdfStream.Length ) );
Response.BinaryWrite( pdfStream.ToArray() );

Response.End();
}

Thanks,
Vishnu

Nov 16 '06 #1
1 3324
Well, you are having it open TestData.aspx, but the CURRENT page is the
one that is processing the data.

What I would do is add a query parameter to TestData.aspx which you can
use to load the document in THAT request when the new window opens.

Also, you might want to revise your GetMinuteOrderPdf routine to take a
stream to write to, since you are basically performing the write for your
PDF document twice.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<se****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="View")
{
LinkButton btn =
e.Item.FindControl("linkView") as LinkButton;

Label lbl=e.Item.FindControl("lblText") as Label ;
sp.DmsID=lbl.Text;
GetPDFDoc(sp);
btn.Attributes.Add("Onclick","window.open('TestDat a.aspx');" +
"return false;");
}
}
Here is the GetPDF function:
public void GetPDFDoc(SearchParams sp)
{
//Tentative tr=new Tentative();
Minute min=new Minute();

MemoryStream pdfStream = new MemoryStream();

pdfStream = min.GetMinuteOrderPdf(sp);

Response.Clear();
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader( "content-length", System.Convert.ToString(
pdfStream.Length ) );
Response.BinaryWrite( pdfStream.ToArray() );

Response.End();
}

Thanks,
Vishnu

Nov 16 '06 #2

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

Similar topics

7
by: Evan Kontos | last post by:
I am using the window.open function to open a small window and I am using GET to get values back from that window. I want to be able to open another from the second window but I get an error...
0
by: Laura Zeafla via .NET 247 | last post by:
I have an application I wrote using the Windows Form Application(.NET) wizard. Pressing a button calls a function in a dllwritten in Visual C++. This function is supposed to cause acommand prompt...
44
by: Carlos Andr?s | last post by:
Hi everybody. I've got a problem. I'd like to avoid opening a new window when you have pressed the shift key and you click in the left button of the mouse. I've tried the next solution, in the...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
2
by: sjp | last post by:
I need to open new windows only for the purpose of viewing linked images, maybe a dozen or so throughout the site. Using the Target="blank" command is quick, easy and seems like the best way to...
2
by: Keshav Gadia | last post by:
Hi, I am an ASP.net newbie. I am writing a user control that is made up of datagrid with one of the columns opening a new window to display some details on click of the set image. I have...
3
by: Bonzol | last post by:
Vb.Net 2003, 1.1. Web application. Hey there I have this, Response.Redirect("FileFiew.aspx") to go to a new page, but how do I open that page in a new window? So I will have 2 pages...
1
by: sandy21380 | last post by:
Hello, Is there a way of opening an Access form without opening the Access window? Right now when I open the form, the Access window is a lot bigger than the form so I have to resize the Access...
3
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, I've got a C# Web Application written in .NET 2.0 in C#. I'd like to add a "Tree-View" component to the form so that they can easily select the "subject" of the form. However, I would...
15
by: anon | last post by:
I have a page where the ASP script create a table of links i.e. 1 = NextPage.asp?Item=1 2 = NextPage.asp?Item=2 etc What I would like to do is open an new window with this link without any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.