MasterPage in ASP.Net
|
Here in this section we will discuss about master page and its application in asp.net. Master Page is a page which allow us to create a unique design or layout in the application website. A master page gives a good theme or look about the application website and can be used in all the pages or group of pages. The most advantage of using a master page is that it eradicates the problem of writing a same code in all pages.
Here I have explained with an example. Creating a Master Page: Step1:Go to Website Step2: Click Add New Item Step3:Select Master Page Step4:Name the Master Page-> example-> secondmasterpage.master Step5: Clik Add We will see a contentplaceholder appears.We now can design the page accordingly.keeping the contentplaceholder unchaged. ContentPlaceHolder is where the content of the other pages will appear.We can place the contentplaceholder where its needed. As shown in the below screenshots the background colour is changed,there are many buttons added, and also a datalist which is bounded with all the categories name. |
|
Now to add master page to other pages:
Step1: Go to the desired website where the master page will be merged.example->userviewone.aspx
Step2: Go to the source part where the html tags are written.
Step3:
Step1: Go to the desired website where the master page will be merged.example->userviewone.aspx
Step2: Go to the source part where the html tags are written.
Step3:
Here in the above screenshot we can see the html codes.Now Excluding the <div>…..</div> delete all the tags from <!DOCTYPE to </html> including </body>,</form>.<head>.After deleting follow the below screenshot.
Step4:
Step4:
Step5: Now coming to the top most code.
The above code is changed to
Here we can see that after “C#” this code is added MasterPageFile="~/secondmasterpage.master"
Here Secondmasterpage.master is name of the masterpage that we have created.
Step6: also we can see
<asp:Content ID="conten1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
</asp:Content> Is also added.
Now running the page the page will appear like the below screenshots
OutPut:
Here Secondmasterpage.master is name of the masterpage that we have created.
Step6: also we can see
<asp:Content ID="conten1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
</asp:Content> Is also added.
Now running the page the page will appear like the below screenshots
OutPut: