Click here to Skip to main content
14,367,549 members
Rate this:
Please Sign up or sign in to vote.
See more:
i want to set image as background in asp.net.here is my code below.the code is not complete just to include where to set image as background.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>BELLCONSULTS</title>
    <style type="text/css">
     .mn{text-decoration:none}
     #hd{background-image:url(C:\Users\BELLCONSULT\Desktop\bellweb\bellimage\BANNER1.jpg);}

    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:1200px; margin-left:100px; border-style:none">
            <tr>
                <td id="hd"  colspan="3" style="height:110px">

              </td>
            </tr>
            <tr>
Posted
Updated 17-Oct-19 2:23am
Comments
Richard C Bishop 27-Sep-13 16:55pm
   
Do you get a red x in a white box instead of the image?
Member 13004728 16-Mar-17 11:55am
   
it is displaying image in design section but when i run a program image gets disappear
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't refere to a local file in a css that is served via a web server. c:\... makes no sense in this context. Add an url that makes sense. For example an url to a static image from your web application.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Create CSS class and give that css class to body element.It Will work.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>BELLCONSULTS</title>
    <style type="text/css">

 .body
{
background:url("C:\Users\BELLCONSULT\Desktop\bellweb\bellimage\BANNER1.jpg");
background-repeat:no-repeat;
}
    </style>
</head>
<body class="body">;
    <form id="form1" runat="server">
    <div>
        <table style="width:1200px; margin-left:100px; border-style:none">
            <tr>
                <td id="hd"  colspan="3" style="height:110px">

              </td>
            </tr>
            <tr>
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

You are using an incorrect path.
Don't forget to make sure you copy the image itself to your solution's folder


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>BELLCONSULTS</title>
    <style type="text/css">
     .mn{text-decoration:none}
     #hd{"background-image:url(header.jpg);}

    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:1200px; margin-left:100px; border-style:none">
            <tr>
                <td id="hd"  colspan="3" style="height:110px">
 
              </td>
            </tr>
            <tr>
   
Comments
CHill60 20-Oct-17 8:13am
   
The question is over 4 years old and already answered by Solution 1. You do not have to have the image in the solution's folder. Stick to answering new questions where the OP still needs help and make sure your solutions are accurate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100