image urls

J

Jaez

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
 
M

Mark Rae [MVP]

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>


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...
 
E

Eliyahu Goldin

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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
J

Jaez

Thanks folks

works fine




Eliyahu Goldin said:
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jaez said:
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
 
M

Mike

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
 

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,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top