UserControl and Folders

F

Francisco

Hello
I have a usercontrol (MenuBar.ascx)... Now i use this in all my pages (aspx)
en the root (OK!!!!)....
The problem is when i use this in others folders... It lost the links
(graphics, links,....) and i have errors......
What's the solution???? Do I need made the same usercontrol in each
folder?????
I used the usercontrol (menubar) like a template for all my pages (aspx)....
Is very hard put all aspx in the root....
Please help me....
 
G

Guest

Make the links in the user control always relative to the project root--e.g.
"~/images/myLogo.gif".

Bill
 
F

Francisco

right... i use relative links.....
I the root by example:
/images/logo.gif
But when i use this usercontrol in a folder... the user control search:
/newFolder/images/logo.gif
And raise an error....
That's the error!!!!

Plese help me.... What should i do?
 
G

Guest

Use the literal "~" in your links per my example, which represents the
project root and means the search will always start at the top, no matter
where you put your user controls, pages, etc.
 
R

Riki

Francisco said:
ok.
But the error now is:
http://localhost/DemoWeb/~/Images/mmc.gif

Mi VS.Net no understand the literal "~" en my link
The image is in:
http://localhost/DemoWeb/Images/mmc.gif

no exists the folder "~"

~ only works in server controls (or more correctly, in any expression that
is processed on the server). So, for instance:
<img src="~/images/test.gif" runat="server">
or
<asp:Image ImageUrl="~/images/test.gif" runat="server">
will work.

<img src="~/images/test.gif">
will NOT work.

Of course you can also assign these values programmatically, or in a
databinding expression.
 
S

Steven Cheng[MSFT]

Thanks for all's inputs.

Hi Francisco,

I think Riki's suggestion is quite reasonable. The "~" char does maps to
Application root fo asp.net application, but it only works for serverside
control attributes bydefault. The clientside browser won't recognize this
char. As for programatically mapping "~/..." to clientside readable url, we
can use
Control.ResolveUrl method to do the translation.


#Control.ResolveUrl Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuicontrolcl
assresolveurltopic.asp?frame=true

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top