Lovely Professional University: Declaration
Lovely Professional University: Declaration
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgement is made explicitly in the text, nor has
any part been written for me by another person.
Evaluator’s comments:
_________________________________________________________________________________
Marks obtained: ______________________ out of ________________________________________
Part A
1. Create a Master Page for a company’s website which contains an image that is
logo for the company. It must be located in a folder named Master Pages. Also
create a Content Page which uses the Master Page and correctly displays the
website logo. Place the Content Page in a completely different folder. Register
the Master Page in web configuration file.
Ans: -
MasterPage.master
</asp:ContentPlaceHolder></td>
</tr>
<tr>
<td >
<td >
<asp:HyperLink ID="HyperLink3" runat="server">Contact Us</asp:HyperLink>
</td>
</tr>
</table>
content.aspx
<tr>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/3.jpg"/>
</td>
</tr>
</table>
</asp:content>
web.config
<system.web>
<pages masterPageFile="~/Master Pages/MasterPage.master">
</pages>
</system.web>
Result:-
2. Make a Website in which users of your website are allowed to customize the
appearance of your website by selecting different Themes. Some users might prefer
a green theme and other website users might prefer a pink Theme. The start page of
your website contains two HyperLink Controls. Which applies either green Theme
or the pink Theme to the page depending on which link they click on the page body?
Ans: -
Theme.aspx
<td align="right">
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/pink.aspx">Pink</asp:HyperLink>
</td>
</tr>
<tr>
<td align="center" colspan="2" >
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Choose Theme And View the
Effect"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
Theme.aspx.cs
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["bg"] != null)
{
Page.Theme = Session["bg"].ToString();
}
}
Green.aspx.cs
Session["bg"] = "green";
Response.Redirect("Theme.aspx");
pink.aspx.cs
Session["bg"] = "pink";
Response.Redirect("Theme.aspx");
Green.skin
Green.css
body
{
background-image:url('green.jpg');
}
pink.skin
pink.css
body
{
background-image:url('pink.jpg');
}
Result-
3. Make a TreeView Control which is populated using an XML file. This XML file is
divided into four categories of available options: Motherboard, Memory,
HardDrives and Drives. These options further provide sub options for additional
information of the parent option. Create a hierarchical list in such a way that
enables users to select multiple options from the list in order to receive additional
information about them. In order to do so, apply the CheckBox controls next to the
leaf nodes within the hierarchical list of nodes. Bind the TreeView Control to this
XML file.
Ans: -
XMLFile.xml
Default.aspx
<div>
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1"
ImageSet="BulletedList" ShowExpandCollapse="False">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
HorizontalPadding="0px" VerticalPadding="0px" />
<DataBindings>
<asp:TreeNodeBinding DataMember="Item" ValueField="Name" />
<asp:TreeNodeBinding DataMember="ItemValue" ShowCheckBox="True"
ValueField="Value" />
</DataBindings>
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml">
</asp:XmlDataSource>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Show Info" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
</div>
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
TreeNodeCollection abc=TreeView1.CheckedNodes;
foreach (TreeNode node in abc)
{
Part B
4. Make a Website in which users are allowed to select the background colour according
to their preference. In future, whenever they visit the WebSite, the chosen
background colour must appear in the WebPage. In order to do so, use the concept
of Session state and save the Session state in a Microsoft SQL Server database.
Ans: -
Default.aspx
</tr>
<tr>
</td>
</tr>
</table>
Default.aspx.cs
SqlDataReader rd;
rd = cmd.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
Session["color"] = rd[0].ToString();
}
Response.Redirect("Default2.aspx");
}
Default2.aspx
Default2.aspx.cs
cmd.ExecuteNonQuery();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
Result
Q5. Make a WebSite which uses the Menu Control with the MultiView control on the
start page of your WebSite. Create the tabbed WebPages within the WebSite. Use
the Menu Control to display the tabs and the MultiView Control to display the
content that corresponds to the selected tab.
SOL: -
</div>
</form>
</body>
</html>
Output:
Q6. Make a Website in which users are allowed to select the background colour
according to their preference. In future, whenever they visit the WebSite, the chosen
background colour must appear in the WebPage. In order to do so, use the concept
of Cookies to save the user’s preference.
SOL: -
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["BackgroundColor"] != null)
{
ColorSelector.SelectedValue = Session["BackgroundColor"].ToString();
BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
}
}
Label1.Text = Session.Timeout.ToString();
}
}