masterpage chapter asp.net
masterpage chapter asp.net
Content Pages
You define the content for the master page's placeholder controls
by creating individual content pages, which are ASP.NET pages
(.aspx files and, optionally, code-behind files) that are bound to a
specific master page. You can bind MasterPage to a content page
by adding MaserPageFile attribute in @ Page directive.This
attribute specifies a master page to be used. For example, a
content page might have the following @ Page directive, which
binds it to the Master1.master page.
<body>
<form id="form1" runat="server">
<div>
<table border="1">
<tr>
<td colspan="2" style="text-align: center">
<h1>Header</h1>
</td>
</tr>
<tr>
<td style="text-align: center; height: 480px; width:
250px">
<h1>Menu</h1>
</td>
<td style="text-align: center; height: 480px; width:
700px">
<asp:ContentPlaceHolder
ID="MainContentPlaceHolder1" runat="server">
<h1>you can change Content here</h1>
</asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<h1>Footer</h1>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Go to the design mode and you will see the image, as shown below.
Step 3:-Adding the Content Pages to Master Page
Page.Theme = Theme1;
Uses of Themes :-
Since themes can contain CSS files, images and skins, you can
change colors, fonts, posi oning and images simply by applying
the desired themes.
You can have as many themes as you want and you can switch
between them by se ng a single a ribute in the web.config
file or an individual aspx page. Also you can switch between
themes programma cally.
Answer
1. Solu on Explorer -> Right click -> Add ASP.NET folder ->
Themes.
3. Theme1 -> Right click -> Add new item -> Stylesheet -> name
it as Theme1.css
Inside Theme1.css
body
{
background-color:Red;
}
App_Themes -> Right click -> Add ASP.NET folder -> Themes
5. Themes2 -> Right click -> Add new item -> Stylesheet ->
name it as Theme2.css
public ThemeTest()
{
this.PreInit+=new EventHandler(Page_PreInit);
}
What is caching?
Caching is one of the most interes ng concepts and
opera ons in ASP.NET. If you can handle it, you can run any web
applica on by applying the caching concept depending on the
requirements. Currently, a majority of websites/portals (or I can say
simply web pages) are dynamic (if I do talk about a dynamic website,
then it doesn't mean all the pages of that website are dynamic or will
be. The probability of happening this is dependent on the user's
perspec ve and the requirements). In very common words I can define
dynamic pages as including the following:
Types of caching
Page Caching Let's explore the caching of an entire page, first.
To cache an entire page's output we need to specify a directive
at the top of our page, this directive is the @ OutputCache.
Let's figure out a simple demo of it.
<%@ OutputCache Duration = 5 VaryByParam = "ID" %>
Here, in that statement Duration and VarByParam are the two
attributes of the OutputCache directive. Now let's explore how
they work.
Duration Attribute: This attribute represents the time in
seconds of how long the output cache should be stored in
memory. After the defined duration the content stored in
the memory will be cleared automatically.
VarByParam Attribute: This is the most important
attribute; you can't afford to miss that in the
OutputCache directory statement. It generally defines the
query string parameters to vary the cache (in memory).
You can also multiple parameter names, but for that, you need
to separate them using a semicolon (;). You can also specify it
as "*". In this case, the cached content is varied for all the
parameters ed using the query string. For example.
<%@ OutputCache Duration = 5 VaryByParam = "*" %>
In the case of caching a page, some pages can generate
different content for different browsers. In that scenario, we
need to add an attribute to our statement to overcome the
preceding problem. For example.
<%@ OutputCache Duration = 5 VaryByParam = "ID"
VaryByCustom = "Browser" %>
Or
<%@ OutputCache Duration = 5 VaryByParam = "*"
VaryByCustom = "Browser" %>
Fragment caching
In some scenarios, we only need to cache only a segment of a
page. For example, a Contact Us page on the main page will
be the same for all the users and for that, there is no need to
cache the entire page.
So for that, we prefer to use the fragment caching option. For
example.
<%@ OutputCache Duration = 10 VaryByParam = "None" %>
Or
<%@ OutputCache Duration = 5 VaryByParam = "None"
VaryByCustom = "Browser" %>
Data Caching
Data caching is slightly different from the 2 other caching types.
It's much more interesting to see how data caching works. As we
know in C# everything is about classes and objects. So
ASP.NET supports data caching by treating them as small sets
of objects. We can store objects in memory very easily and use
them depending on our functionality and needs, anywhere
across the page. Now you must be thinking where is the class in
that entire scenario? This feature is implemented using the
Cache class and data is treated as its object. Let's see how it
works using a demo. I am inserting a string value in the cache
as.
Cache["Website"] = "CSharpCorner";
Now, for inserting the cache into the objects, the insert method
of the Cache class can be used. This insert method is used as
follows.
Cache.Insert("Website", strName,
new CacheDependency(Sever.MapPath("Website.txt"));
What we are missing is something We missed the Time for the
cache (don't forget to use it), let's provide it.
Cache.Insert("Website", strName,
new CacheDependency(Sever.MapPath("Website.txt")
DateTime.Now.Addminutes(5), TimeSpan.Zero);