Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Server Tag Not Parsing in URL Field

Posted on 2014-04-23
2
Medium Priority
?
404 Views
Last Modified: 2014-04-24
Experts,

I'm banging my head against a wall here, and I'm sure this is a simple syntax issue.  I am working with a ListView control, and I'm trying to construct a hyperlink that parses a datafield into the query string of a URL (the page that is being called in the URL serves the image data from the provided filename back as a filestream because the image being called resides in a location outside the application folder.)

<asp:HyperLink	runat="server"
		NavigateUrl='~/ServeFFAttachment.aspx?FileName=<%# Eval("ATTACHMENT_PATH") %>'
		Target="_blank">
	<%# Eval("ATTACHMENT_DESC") %>
</asp:HyperLink>

Open in new window


The server doesn't choke on the code, but the URL that gets associated with the hyperlink isn't evaluating the server tag (see below.)

http://serverfqdn:55555/ServeFFAttachment.aspx?FileName=<%# Eval("ATTACHMENT_PATH") %>

Open in new window


I should point out that this worked fine before I added the ASPX page to the URL (code below worked...)

<asp:HyperLink	runat='server'
		NavigateUrl='<%# Eval("ATTACHMENT_PATH") %>'
		Target='_blank'>
	<%# Eval("ATTACHMENT_DESC") %>
</asp:HyperLink>

Open in new window


Why does adding "~/ServeFFAttachment.aspx?FileName=" before the Server Tag mess it up??

HELP!!  :-)

Thanks,

John
0
Comment
Question by:John Parker
[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
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40018381
When you want to include a binding value in the url attribute, the whole value needs to be generated from within the asp tags.

One possible way would be:
NavigateUrl='<%# Eval("ATTACHMENT_PATH", "~/ServeFFAttachment.aspx?FileName={0}") %>'

Open in new window


Note that the query parameter in your generated url should actually be url encoded to make valid html, if that's important in your case you could try something like:
NavigateUrl='<%# String.Format("~/ServeFFAttachment.aspx?FileName={0}", HttpUtility.UrlEncode(Eval("ATTACHMENT_PATH"))) %>'

Open in new window

0
 

Author Closing Comment

by:John Parker
ID: 40021012
Robert,

That was it!  Thank you very much for the quick response!  I did have to make one minor change to the use of the URLEncoded function...  I had to add the ToString method to the Eval function for it to work.  Otherwise the compiler didn't like it.

NavigateUrl='<%# String.Format("~/ServeFFAttachment.aspx?FileName={0}", HttpUtility.UrlEncode(Eval("ATTACHMENT_PATH").ToString())) %>' 

Open in new window


Thanks again!

John
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

604 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