OnSelectedIndexChanged - New Browser Window

G

George Durzi

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"
Text='<%#DataBinder.Eval(Container, "DataItem.Title")%>'
CommandName="Select" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

The data source is a table of PDF files. It contains the Id, the path to the
file, and the title of the file. On the SelectCommand event of the DataGrid,
all I'm doing is streaming the PDF file to the browser:

protected void dgReader_OnSelectedIndexChanged(object sender,
System.EventArgs e){
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(dgReader.SelectedItem.Cells[1].Text);
Response.Flush();
Response.Close();
}

When I click the select button, I'd like the streaming of the PDF to happen
in a new window.

One very important thing is that I can't pass a query string in the URL (to
prevent URL tampering). Of course, I could do this with a Guid if that's
what it came down to.

Thanks a million for your help
 
J

John Saunders

George Durzi said:
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"
Text='<%#DataBinder.Eval(Container, "DataItem.Title")%>'
CommandName="Select" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

The data source is a table of PDF files. It contains the Id, the path to the
file, and the title of the file. On the SelectCommand event of the DataGrid,
all I'm doing is streaming the PDF file to the browser:

protected void dgReader_OnSelectedIndexChanged(object sender,
System.EventArgs e){
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(dgReader.SelectedItem.Cells[1].Text);
Response.Flush();
Response.Close();
}

When I click the select button, I'd like the streaming of the PDF to happen
in a new window.

You can't create a new window from the server. Only the client can do that.

Instead of the LinkButton, you could use a HyperLink, with Target="_blank".
Use a GUID in the query string of the URL, and have the newly-requested page
translate that GUID into the PDF file which the second page would stream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top