Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4301
  • Last Modified:

click Image button to open file url

I have an image button in a datagrid, and I need to open a word document.  Can I specify a file url, and if so, how?  Right now my image button is defined as:

<asp:ImageButton class="Image" id="imgDetails" title="Details" runat="server" CommandName="Details"
src="images/ico_Details.gif"></asp:ImageButton>

and on the ItemCommand event is where I want to specify to open a word document thats name is dependent on a couple cells in the grid:

open file url ""file://path/" + e.Item.Cells[1].Text + e.Item.Cells[3].Text + ".doc";

Can anyone help? trying to write this in asp.net c#...

0
michael1174
Asked:
michael1174
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
surajgupthaCommented:
You can open a new window in javascript passing the url constructed from the grid's cells
0
 
Elvio Lujan.Net Senior DeveloperCommented:
just use in the itemcommand method a

Response.Redirect("yourfile");
0
 
michael1174Author Commented:
I'll try your suggestion ,but I do need to open it up in a new window....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
surajgupthaCommented:
This is how u can open this new window
<INPUT type="button" value="New Window!" onClick="window.open('jex5.htm','mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')">

But the value of the url should also be constructed at run time using javascript.. By using javascript you prevent an unnecessary round trip to the server.
0
 
michael1174Author Commented:
I just tried :

Response.Redirect("//file:////path/" + e.Item.Cells[1].Text + e.Item.Cells[3].Text + ".doc");

and it didn't work, it gave me local host and the aspx that I was on...
0
 
ChumadCommented:
Can you change it to a standard img and not use a built in button? Problem you'll run into is outputting javascript from an onclick event (it's doable, but messy.) Instead, you could do something like this:

<a href='<%# String.Format("file://path/{0}", Bind("fieldName"))  %>'><img src='images/ico_Details.gif'></a>
0
 
michael1174Author Commented:
surajguptha, I need those valus in the grid cells in order to construct the name of the documnet, so how can i get the values at runtime?
0
 
Elvio Lujan.Net Senior DeveloperCommented:
use

response.write("<script>window.open('yourFile')</script>")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now