Blog
Enterprise Application Development BSCS 7th Term Past Paper 2019 UOS
University of Sargodha BS 7th term Enterprise Application Development (CMP-4744, new course) past paper 2019, retyped from the original paper, with solved answers below.
Solved answers
Q1 – Short questions
(i) The ScriptManager control is required on every page that uses ASP.NET AJAX Extensions (UpdatePanel, UpdateProgress, Timer).
(ii) System.Web.UI.Control is the base class of all server controls (web server controls further derive from System.Web.UI.WebControls.WebControl).
(iii) Session state modes: Off, InProc, StateServer, SQLServer and Custom. InProc (the default) stores session state in the memory of the web server (worker process).
(iv) Global.asax: the application file that handles application-level and session-level events, e.g. Application_Start, Application_End, Application_Error, Session_Start, Session_End, Application_BeginRequest.
(v) Postback vs Callback: in a postback the whole page is submitted to the server, the full page life cycle runs and the complete page is re-rendered. In a callback, client script sends a lightweight request; the server runs only part of the life cycle (ICallbackEventHandler) and returns just the needed data, so the page is not reloaded.
(vi) Label vs Literal: a Label renders its text inside a <span> tag and supports style properties (CssClass, ForeColor, AssociatedControlID). A Literal renders only the text without any wrapping tag and has no styling properties.
(vii) Build providers: classes that generate source code at compile time for particular file types (e.g. .xsd, .wsdl, .resx, .edmx) so that strongly typed classes are available. Syntax in web.config:
<compilation>
<buildProviders>
<add extension=".abc" type="MyNamespace.MyBuildProvider" />
</buildProviders>
</compilation>(viii) RegisterClientScriptBlock places the script at the top of the form, right after the opening <form> tag, before the page’s controls are rendered — so it cannot access them while loading (good for function definitions). RegisterStartupScript places the script at the end of the form, so it runs after all elements are loaded and can access controls.
(ix) DropDownList vs ListBox: a DropDownList shows one item at a time and allows only a single selection. A ListBox shows several items at once (Rows property) and allows multiple selection with SelectionMode=”Multiple”.
(x) Text vs ErrorMessage: Text is displayed at the location of the validator control itself; ErrorMessage is displayed in the ValidationSummary control. If Text is empty, the ErrorMessage is shown in both places.
(xi) MasterPage: a .master file that defines a common layout (header, menu, footer) with ContentPlaceHolder controls; content pages fill those placeholders. A website can have any number of master pages (and nested master pages), but each content page uses one master page at a time.
(xii) File server architecture: data files are kept on a shared file server; each client runs the whole application and the file server only stores files. The entire file is transferred over the network for processing, so network traffic is heavy, concurrency control and security are weak and it does not scale — client–server and multi-tier architectures replaced it.
(xiii) Compilation diagram: Source code (C#/VB.NET) → language compiler (csc/vbc) → Assembly (MSIL + metadata, .dll/.exe) → CLR JIT compiler at run time → native machine code → execution.
(xiv) The PreRender event (Page_PreRender). It occurs after all control events and before the view state is saved and the page is rendered, so it is the last point where changes to the page or its controls are persisted.
(xv) The App_Code folder — source files placed there are compiled automatically at run time and are available to every page of the website.
(xvi) 4 MB (maxRequestLength = 4096 KB in httpRuntime); it can be increased in web.config.
Q2 – HTML control vs HTML server control
An HTML control is an ordinary HTML element (e.g. <input type=”text”>) that is sent to the browser as it is; the server cannot access it in code and its state is not kept between postbacks.
An HTML server control is an HTML element with runat="server" and an id, e.g. <input type="text" id="txtName" runat="server" />. ASP.NET creates an object for it from the System.Web.UI.HtmlControls namespace, so it can be used in server code (txtName.Value), handles server events and maintains view state.
All HTML server controls derive from the HtmlControl class and are divided into these classes:
- HtmlContainerControl — elements with opening and closing tags: HtmlForm, HtmlAnchor, HtmlButton, HtmlGenericControl (div, span), HtmlSelect, HtmlTable, HtmlTableRow, HtmlTableCell, HtmlTextArea.
- HtmlInputControl — <input> elements: HtmlInputText, HtmlInputButton, HtmlInputCheckBox, HtmlInputRadioButton, HtmlInputFile, HtmlInputHidden, HtmlInputImage, HtmlInputSubmit/Reset.
- Other: HtmlImage (<img>), HtmlHead, HtmlTitle, HtmlLink, HtmlMeta.
Q3 – Fill a DropDownList from the database
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
public partial class Classes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) { LoadClasses(); }
}
private void LoadClasses()
{
string cs = ConfigurationManager.ConnectionStrings["SchoolDB"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("SELECT ClassID, ClassName FROM Class", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
ddlClasses.DataSource = dr;
ddlClasses.DataTextField = "ClassName";
ddlClasses.DataValueField = "ClassID";
ddlClasses.DataBind();
}
// first entry "Select" at the top
ddlClasses.Items.Insert(0, new ListItem("Select", "0"));
}
}
<!-- in the .aspx page -->
<asp:DropDownList ID="ddlClasses" runat="server"></asp:DropDownList>Q4 – Compilation and precompilation
Compilation converts the source code of pages and classes into MSIL assemblies. By default ASP.NET uses dynamic compilation: each page is compiled the first time it is requested, which makes the first request slow.
In-place precompilation: the site is compiled where it is (on the server) so the first user does not wait, and compile errors are found in advance. The source files remain in place and the compiled output goes to the Temporary ASP.NET Files folder. Command: aspnet_compiler -v /MyWebsite (or request the special page precompile.axd).
Precompilation for deployment: the site is compiled into a separate target folder that contains assemblies in the bin folder and placeholder files instead of the source code, which is then copied to the production server. It protects the source code and gives the fastest start-up. Command: aspnet_compiler -v /MyWebsite -p C:\Projects\MyWebsite C:\Deploy\MyWebsite; add -u to keep .aspx markup updatable, and -f to overwrite the target.
Q5
i. UpdatePanel control: an AJAX control that allows partial-page updates. Only the content inside its ContentTemplate is refreshed during an asynchronous postback, so the whole page is not reloaded. It needs a ScriptManager on the page; UpdateMode (Always/Conditional) and Triggers (AsyncPostBackTrigger, PostBackTrigger) control when it refreshes.
ii. Page_Load event: raised on every request after the page and its controls are initialised and view state is restored; used to set control values, bind data, etc. IsPostBack is checked so that one-time initialisation (like loading a list) runs only on the first request.
iii. CompareValidator: compares the value of an input control with another control (ControlToCompare) or a constant (ValueToCompare) using an Operator (Equal, NotEqual, GreaterThan, LessThan, DataTypeCheck…) and Type (String, Integer, Date, Double, Currency). Typical use: confirm password, or date range checks.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTime" runat="server" />
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" />
<asp:TextBox ID="txtConfirm" runat="server" TextMode="Password" />
<asp:CompareValidator ID="cvPassword" runat="server"
ControlToValidate="txtConfirm" ControlToCompare="txtPassword"
Operator="Equal" Type="String"
ErrorMessage="Passwords do not match" ForeColor="Red" />Q6 – Page life cycle
When a page is requested, ASP.NET creates the page object and runs it through a series of stages. Events in calling order:
- PreInit — check IsPostBack, set master page and theme dynamically, create dynamic controls.
- Init — each control is initialised; control properties can be read/initialised.
- InitComplete — view-state tracking is turned on.
- (LoadViewState / LoadPostData on postback) — saved view state and posted form values are restored to controls.
- PreLoad — after view state and postback data are loaded.
- Load — Page_Load runs for the page and then for each child control.
- Control events — e.g. Button.Click, TextChanged, SelectedIndexChanged.
- LoadComplete — after all event handling.
- PreRender — final changes before rendering (DataBind for data controls).
- PreRenderComplete.
- SaveStateComplete — view state and control state are saved.
- Render — not an event; each control writes its HTML output.
- Unload — clean-up: close connections and files; the response has been sent.
Q7 – XML
XML (eXtensible Markup Language) is a text-based markup language for storing and transporting data in a structured, self-describing, platform-independent way using user-defined tags. It must be well-formed (one root element, properly nested and closed tags) and can be validated with DTD/XSD.
Uses: data exchange between different applications and platforms, web services (SOAP, WSDL), configuration files (web.config, app.config), RSS feeds and sitemaps, storing small amounts of data, and with DataSets (ReadXml/WriteXml).
using System.Xml;
protected void btnCreate_Click(object sender, EventArgs e)
{
XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
string path = Server.MapPath("~/App_Data/students.xml");
using (XmlWriter writer = XmlWriter.Create(path, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("Students");
writer.WriteStartElement("Student");
writer.WriteAttributeString("id", "1");
writer.WriteElementString("Name", "Ali");
writer.WriteElementString("Class", "BSCS");
writer.WriteEndElement(); // Student
writer.WriteEndElement(); // Students
writer.WriteEndDocument();
}
lblMsg.Text = "XML file created.";
}The file produced:
<?xml version="1.0" encoding="utf-8"?>
<Students>
<Student id="1">
<Name>Ali</Name>
<Class>BSCS</Class>
</Student>
</Students>Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.
