Today in Engineer's World, we are
discussing a C# query faced by a
developer in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS
Which page is called first in asp.net c#? Web form or Master page?
Code that we write on the master page.
Practical Implementation:
<body>
Code that we write on web form page
Practical Implementation:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Now, the question arises
We got the output as master page label called first and content page label called after master page.
(A) 1 only
Which page is called first in asp.net c#? Web form or Master page?
One such scenario is - Suppose you have a
master page and a nested web form page. In your master page, you write some
piece of code. Like, you add a label control and write its Text property as
“Master Page Load” with Red color.
Note: We haven’t written any code in
the code-behind for any page (neither in master nor in web form page).
Code that we write on the master page.
Practical Implementation:
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Master
Page Load" ForeColor="Red"></asp:Label>
<br />
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
In the same manner, you add a label
control and write its Text property as “Content Page Load” with Red
color.
Code that we write on web form page
Practical Implementation:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Content
Page Load" ForeColor="Red"></asp:Label>
<br />
</asp:Content>
Now, the question arises
Which page label control is called
first? Is it the Default.aspx or MasterPage.master?
Let’s run and check.
Output:
We got the output as master page label called first and content page label called after master page.
Reason explanation: We have taken
server control. And server control renders. And as per the event sequence of
pages – Web Form page control load after Master Page control. That’s why Master
Page Control Render first than Content Page.
Related
Questions:
Q-1 Which of the following is an
ordered collection class?
1) Map
2) Stack
3) Queue
4) BitArray
5) HashTable
(A) 1 only
(B) All the
above
(C) 2 and 3
only
(D) 2 and 5
only
(E) 4 and 5
only
Ans. Option(C)
Q-2 What is the base class from
which all Web forms inherit?
A) Page Class
B) Session
Class
C) Master
Page
D) None of
the Above
Ans. Option(A)
Keep learning and
sharing…
No comments:
Post a Comment