Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between <head> and <asp:Content ID="HeaderContent" ...>?

This may be a newbie question, but i'm pretty new to asp.net & C# etc.

I'm working with an ASP.net website, and I'm curious about the structure of it (after automatically creating a web project), specifically the following:

I see that in Default.aspx , I have a tag like this:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>**strong text**

But in Site.master, I have this:

<head runat="server">
*etc*
</head>

So where would I put code if I wanted to include JavaScript code to run, on page load?

like image 392
Caffeinated Avatar asked Dec 12 '22 17:12

Caffeinated


1 Answers

I believe you can put your code in any of them. The first one is for adding code or script used by all content pages(that using this master page file) while the second one is if you want to to add script or code from content pages(that should be used only for this specific page)

//in the Master page, the content here is used by all content pages
<head runat="server">
*etc*
</head>

and

//this is specific to the content page that use it. This section needs to be supplied in content pages
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>

That section needs to be supplied in each content page and it will be exclusive to that page - no other page can use the script in that section

like image 108
codingbiz Avatar answered Dec 14 '22 07:12

codingbiz