0% found this document useful (0 votes)
395 views

Tutorial 8 Answer

The document discusses master pages and user controls in ASP.NET. Master pages allow the creation of a common layout that can be applied to multiple pages, defining placeholders for variable content. User controls encapsulate reusable groups of controls and code that can be used across some pages. The document provides examples of when each would be best to use - master pages for elements that should appear on all pages, and user controls for elements that may vary between some pages.

Uploaded by

miChiKoLee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
395 views

Tutorial 8 Answer

The document discusses master pages and user controls in ASP.NET. Master pages allow the creation of a common layout that can be applied to multiple pages, defining placeholders for variable content. User controls encapsulate reusable groups of controls and code that can be used across some pages. The document provides examples of when each would be best to use - master pages for elements that should appear on all pages, and user controls for elements that may vary between some pages.

Uploaded by

miChiKoLee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

ACS4134 Internet Programming

Tutorial 8 (solution) Q1 (a) Describe Master Page and user control. Both are code reduce features and reusability purpose User control is a control that has to be added into a page, while Master Page serves like a template, where we add the ContentPlaceHolder in the Master Page to display the child page.

User Control: is an ASP.NET page that has been converted into a control. User control is a group of one or more server controls or static HTML elements that encapsulate a piece of functionality Enable you to reuse the same content and programming logic on multiple ASP.NET pages. Saved with a .ascx file extension and can be called from any of the ASP.NET pages in any application. Master Page A Master page defines the layout to be used by all pages based on the Master. Allows you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. the extension is .master. A master page is a template for other pages, with shared layout and functionality. The master page defines placeholders for content pages. The result page is a combination (merge) of the master page and the content page.

Q1 (b) Discuss the reasons of using User Controls in a Website over Master Page. User controls are great to encapsulate markup, controls and code that you need repeatedly throughout your site, but should only appear on some but not all pages (While Master Pages allow you to create content that is displayed in all pages in your site) Q2 (a) You wish to add common functionality in all pages. For example every page will consist of a common header and footer. Master Page - Using masterpage, all the header and footer we can add in one master and use it any page Q2 (b) There are 3 different groups of users who can login to the application. Different groups of users will see different advertisement banner after they login to a shopping page. User controls are great to encapsulate markup, controls (that display the advertisement differently) and code (to verify the group of user) that you need repeatedly throughout your site, but should only appear on some but not all pages.
Chapter 9 Reusable Code

ACS4134 Internet Programming

You answers should include the explanation of your choice. Q3. Briefly describe the differences between a user control and a custom control. Please refer to chapter 8 lecture notes Q4. TagPrefix TagName Src myControl ProgressBar Bar.ascx

<%@ Register TagPrefix="myControl" TagName="ProgressBar" Src="bar.ascx" %> <myControl:ProgressBar ID="bar" runat="server" /> Q5. <control:Header ID="ctlHeader" runat="server"/> <control:Menu ID = ctlMenu runat = server /> <login:Main ID= ctlLogin runat= server />
<%@ Register TagPrefix="control" TagName="Header" Src="header.ascx" %> <%@ Register TagPrefix="control" TagName="Menu" Src="menu.ascx" %> <%@ Register TagPrefix="login" TagName="Main" Src="login.ascx" %>

Q6. string strRole = ""; string strSrc = ""; if (Session["role"] != null) { strRole = Session["role"].ToString(); } if (strRole == "Member") strSrc = "member.ascx"; else if (strRole == "Admin") strSrc = "admin.ascx"; else strSrc = "general.ascx"; Control ctrBanner = LoadControl(strSrc); phBanner.Controls.Add(ctrBanner);

Chapter 9 Reusable Code

You might also like