开发者

Add an image into header area

can I insert an image to the web page header area? The master page code is:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>

And the web page code

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"><img src="Images/cross.jpg" />

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
</asp:Content>

Can I insert an image to the header area. Then the header code becomes

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"><img src="Images/cross.jpg" />    
<开发者_如何学Python;/asp:Content>

Thanks.


To quote w3schools:

The head element is a container for all the head elements. Elements inside can include scripts, instruct the browser where to find style sheets, provide meta information, and more.

In the default Visual Studio 2010 new web site template, the HeadContent area in the default master page allows you to add elements to the <head> section. This is NOT to be confused with the "head" banner on the page! If you want to edit the login control that is in the "header" div, edit Site.master.

Hopefully this clears up your misunderstanding, if you need additional direction just leave a comment.


Why would you want to do that? Putting an image into the HEAD section of HTML is invalid and, for all .NET would complain, you'd have very unexpected results in the browser and your HTML wouldn't validate.


For most "can I do this weird thing?" questions, you're best off trying them to see the results. But yeah, this is probably going to yield really wonky behavior in web browsers, at best. And it's definitely not going to be valid HTML.

If you're trying to load an image into memory for use later, but you don't want it to be shown to the user, a better way is to put it into the body and then use CSS to hide it via display: none;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜