Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 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.
XML
<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 1: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

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.
 
Share this answer
 
Create CSS class and give that css class to body element.It Will work.

XML
<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>
 
Share this answer
 
v2
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>
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900