Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 01:31 PM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ImageUrl in aspx page

I've got a web form coded behind with C#. The form has a datagrid control inside of it and within that there's a templated column that contains an imagebutton control. The imagebutton control sets the ImageUrl property as follows:

Code:
<asp:imagebutton ... ImageUrl="<%# GetImageDirectory() %>myimage.gif"...> ... </asp:imagebutton>
Now the problem is that the HTML that is output interprets the directive literally outputting as the image button's image source: "<%# GetImageDirectory() %>myimage.gif"

Now I've successfully bound date using this format as in:

Code:
Text="<%# DataBind.Eval...."
so why doesn't this work?

 
Old October 7th, 2004, 04:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What does GetImageDIrectory() do?
 
Old October 8th, 2004, 07:10 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Image directory, my own func, just returns the root of the image directory as a string.

 
Old October 8th, 2004, 05:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Maybe because a returned string is not a bindable collection, as denoted by <%# %>. Not 100% sure about that. Try changing <%# %> to <%= %>, or alter the ImageUrl property at runtime.

Brian
 
Old October 16th, 2004, 03:46 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Typically when you need to put databinding syntax inside a markup attribute you use single quotes:

<asp:imagebutton ... ImageUrl='<%# GetImageDirectory() %>myimage.gif'...> ... </asp:imagebutton>

However, if you are simply looking to have something that gives you the root image directory, you can use a piece of built-in functionality:

<asp:imagebutton ... ImageUrl="~/images/myimage.gif"...> ... </asp:imagebutton>

ASP.NET will automatically replace the ~ with the application root directory. You can then make a root relative reference to any resource using that syntax. However, it may not solve the problem if you need a truly dynamic images directory.
 
Old October 18th, 2004, 08:32 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent. Thanks for the valuable info!






Similar Threads
Thread Thread Starter Forum Replies Last Post
ImageUrl syntax almotions ASP.NET 2.0 Basics 2 January 24th, 2008 03:47 AM
How to pass variables from Aspx page to Asp Page jayaraj Classic ASP Basics 2 May 23rd, 2004 06:56 AM
How to pass the variables in Aspx page to Asp Page jayaraj ASP.NET 1.0 and 1.1 Basics 3 May 23rd, 2004 06:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.