On an aspx page I am trying to place an image which can be clicked on to
download a file. Neither the image or the url of the doc are known until
runtime
Textbox1.text contains the url of a word document and textbox2.text contains
the url of a png graphic
Please can someone help me with the syntax as this does not work
<a href='<%# textbox1.text %>'>
<img src='<%# textbox2.text %>' style="width: 60px; height: 60px" /></a>
jaez
Mark Rae [MVP] - 08 Oct 2007 15:11 GMT
> On an aspx page I am trying to place an image which can be clicked on to
> download a file. Neither the image or the url of the doc are known until
[quoted text clipped - 8 lines]
>
> <img src='<%# textbox2.text %>' style="width: 60px; height: 60px" /></a>
How are you populating the page...?
<%# is databinding syntax - if you just want to refer to the text in the
textbox, try:
<%=textbox1.txt%>
However, depending on how you are fetching / populating the initial data, it
may not be available when the control is rendered...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Eliyahu Goldin - 08 Oct 2007 15:20 GMT
You can keep your syntax if you wish, just add runat=server and call
DataBind method for the page.
Or you can use <%= syntax:
<a href='<%= textbox1.text %>'>
Or you can use server controls HyperLink and Image and set their attributes
programmatically.

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
> On an aspx page I am trying to place an image which can be clicked on to
> download a file. Neither the image or the url of the doc are known until
[quoted text clipped - 10 lines]
>
> jaez
Jaez - 08 Oct 2007 19:17 GMT
Thanks folks
works fine
> You can keep your syntax if you wish, just add runat=server and call
> DataBind method for the page.
[quoted text clipped - 19 lines]
>>
>> jaez
Mike - 09 Oct 2007 19:57 GMT
why would you use a textbox as an image?
why not just use the <img> tag?
I'm doing something like this to populate an image based on what is returned from the db.
public string GetDocImage(object docName)
{
string strImg;
if(docName== DBNull.Value)
{
strImg = "~/images/empty.gif";
}
else
{
strImg = "~/images/Docname" + docName+ ".gif";
}
return strImg;
}
and in the HTML, I do this:
<asp:Image ID="imgDoc" runat="server" AlternateText='<%# Eval("DocName%>'
ImageUrl='<%# GetDocImage(Eval("docName")) %>' />
this returns the docName and the URL for the document to open
> On an aspx page I am trying to place an image which can be clicked on to
> download a file. Neither the image or the url of the doc are known until
[quoted text clipped - 10 lines]
>
> jaez