 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics 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
|
|
|
|

March 25th, 2006, 01:51 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem with Images in the MasterPage when ....
Hello,
I have a problem with Images in the MasterPage(which is in the root directory) when the content Page is in /members. So I can not use :
=HttpContext.Current.Server.MapPath("~\Images")... because it goes really long and I can not use JavaScript in the buttons, and it is kind of impossible to change the path of every little picture like that.:)
If anybody can give me another way to see this pictures even if the content page is in /member I'll appresiate!
Thanks in advance:)
|
|

March 26th, 2006, 05:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I am not sure what you mean with this:
Quote:
|
quote:HttpContext.Current.Server.MapPath("~\Images ")... because it goes really long and I can not use JavaScript in the buttons
|
Can you elaborate about what you're trying to do?
Why can't you simple reference the images like this:
~/Images/SomeImage.gif
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 26th, 2006, 06:22 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well all the images are in "/images/". Main.master.aspx is in the "/"
I have this image on the main.master:
1. <img src="Images/bmw/bmw.jpg" />
And now I make a content age of that Main.Master.aspx in the /members/ and when i run the content page I can not see the picture of the Main.master. And another content page in the "/" and there I can see the pictures.
2.I've tried with "<img src="~/Images/bmw/bmw.jpg" />" and in this case I can not see the picture in both content pages.
Would you please check it for me if it is the same with you or I have a problem in my software.. It seem to me that I've tried everything
Thank you
|
|

March 26th, 2006, 06:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you have an image like this in your master page:
<asp:Image ImageUrl="~/Images/SomeImage" ... />
then it should appear in the browser in your ASPX page, assuming there is an Images folder in the root of your application...
Are you saying this isn't the case?
Maybe the problem is with this:
<img src="~/Images/bmw/bmw.jpg" />
You are using the ~ syntax, but that only works with server side controls. So, you need to change your <img> tag to a server control, either using <asp:Image> or by adding a runat attribute:
<img src="~/Images/bmw/bmw.jpg" runat="Server" id="SomeImage" />
With a server side image (or other URL driven controls) the ~ is replaced with the application's root.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 26th, 2006, 11:14 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you realy much! The Problem comes runat="server".
Thanks again
|
|

May 11th, 2006, 04:39 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi every one, I am a new subscriber on this form, I am from Jordan, need your help about this problem, after I reed the previous solution I thought it was the solution but i have different situation with this line:
<td colspan="6" style="background-position: center center; background-image: url(~/images/background_main.jpg); height: 116px;" >
I have a background image that will not appear in the same scenario, I add "runat=server" sentence but the problem was still.
Mohd A. Shalabi
|
|

May 11th, 2006, 10:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Using the ~ syntax with a runat="server" attribute only works with properties that are aware of this syntax, like the NavigateUrl of a HyperLink control.
There are a few ways to overcome this:
1. Move the style to a stylesheet file in a separate folder. The you can use ../Images/SomeImage to refer to an image that's inside the Images folder at the same level as the CSS folder is.
2. Write a function that returns the current root at add that to the table tag.
3. Add the style definition in the code behind using myTable.Attributes.Add("style") and then dynamically build up the path to the image.
Personally, I'd go for option 1 because it's easier to make and maintain.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

May 14th, 2006, 07:12 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I dont used a style file...
(if i should make one, please explain what you say)
Mohd A. Shalabi
|
|

May 14th, 2006, 08:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
1. Right-click your project and choose Add Folder. Name the folder CSS.
2. Right-click that folder, choose Add New Item and choose Style Sheet. You'll end up with a new file with a .css extension
3. Add the following rule to that style sheet:
.MyTableCell
{
background-image: url(../Images/background_main.jpg);
background-position: center;
height: 116px;
}
4. Change the <td> with the background to this:
<td colspan="6" class="MyTableCell">
5. Make sure your master pages sees the CSS file. To do this, open the Master Page, switch to design view and then drag and drop the css file from the solution explorer onto your master page.
6. Save and run.
When the page loads, a link to the CSS file has been added to the <head> of the page. That file contains the definition for the MyTableCell class. So, when the browser encounters the class="MyTableCell" rule, it knows where to look for its definition.
Paths used in CSS files are relative to the CSS file, and not to the page where they are used. So:
../Images/SomeImage.jpg
in a style file inside the CSS folder actually means: one level up (which means out of the CSS folder) and then one level down again in the Images folder.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

May 17th, 2006, 05:26 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear my Imar, I would like to thank you so much; you have solved one of my biggest problems I faced on learning ASP.NET 2.00. Actually I would like to learn more about CCS files (always with coded demo example), please remember that I am a beginner programmer in ASP.NET.
One of my other problems:
I have login page that have a background image (no such master page in this case). The picture appears in design mode and after I click logout, but when the site runs first time the picture not appears. But (As I tell you) when I login and make a logout the pasture appears.
This information may help you:
- I used a CCS with a method as the problem you solved to me. (first I used the normal method and no picture appear, when I used CCS the problem still)
- The logout command is (I used the cashed idea to solve back problem):
Session["SessionId"] = null; Response.Redirect("~/Login/Login.aspx");
- No problems appear when I take the project to wwwroot in IIS 6.00 and run the website without VS2005 directly through my browser.
Mohd A. Shalabi
Mohd A. Shalabi
|
|
 |