0% found this document useful (0 votes)
82 views12 pages

Practical 5 Examples Adv - Web Progr.

This document contains examples of using various navigation and styling controls in ASP.NET web forms, including link labels, image buttons, and applying CSS styles. It also demonstrates storing and retrieving user data from server-side states like view state, control state, and hidden fields. The examples show how to redirect between pages, validate login credentials, and send email notifications.

Uploaded by

krishnadev roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views12 pages

Practical 5 Examples Adv - Web Progr.

This document contains examples of using various navigation and styling controls in ASP.NET web forms, including link labels, image buttons, and applying CSS styles. It also demonstrates storing and retrieving user data from server-side states like view state, control state, and hidden fields. The examples show how to redirect between pages, validate login credentials, and send email notifications.

Uploaded by

krishnadev roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Theory-5 :Introduction to Navigation, Beautification and Master

page.
Practical-1:Create Web Form to demonstrate use of Website Navigation
controls and Site Map.

Example-1: Create Web Form to demonstrate use of the LinkLabel Control


for navigating a user from one page to another page.(IT Lab)
Source code:-

using System.Diagnostics;
using System.Windows.Forms;

Namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
Public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, System.EventArgs e)


{
// Add a link to the LinkLabel.
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://c-sharp.com/";
linkLabel1.Links.Add(link);
}

private void linkLabel1_LinkClicked(object sender,


LinkLabelLinkClickedEventArgs e)
{
// Send the URL to the operating system.
Process.Start(e.Link.LinkData as string);
}
}
}

Output:-
Colusion:- This program is running successful.

Example-2: Write a program to display two textboxes to accept username and


password, if username is “abcdef” and password is “12345”, then redirect
The page to another page , else give an error message as “Incorrect username
and password…!”
Source code:-

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
After add namespaces write the following code in code behind

protected void btnSubmit_Click(object sender, EventArgs e)


{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString)
;
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName
=@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script
language='javascript'>alert('Invalid Username and Password')</script>");
}
}

Output:-
Conclusion:- This program is running successful.
Practical-2:Create a web application to demonstrate use of Master Page with
applying Styles and Themes for page beautification

Example-1: Design a Web Form and apply the different styles using CSS.

Source code:-

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<style>
.LabelGrey
{
font-weight: bold;
color: darkgray;
}

.LabelBlue
{
font-weight: normal;
color: darkblue;
}

.ClassJoined
{
font-weight: normal;
font-size: 50px;
color: darkcyan;
}
</style>
<title></title>
</head>

<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMessage" runat="server" Font-Size="25px"
Text="Hello, CSharpCorner Users" CssClass="LabelBlue"></asp:Label>
<br />
<asp:Button ID="btnChangeCSS" runat="server" Text="Change
CSS Class" OnClick="btnChangeCSS_Click" />
<br />
<br />
<asp:Label ID="lblWithoutStyle" runat="server" Text="Text
without any style" />
<br />
<asp:Button ID="btnChangeStyle" runat="server"
Text="Change Style on Click" OnClick="btnChangeStyle_Click" />
<br />
<br />
<asp:Label ID="lblWithoutClass" runat="server" Text="Text
without any default class" />
<br />
<asp:Button ID="btnWithoutClass" runat="server"
Text="Class Attached on Click" OnClick="btnWithoutClass_Click" />
</div>
</form>
</body>

</html>
Code Behind .cs File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangeCSSClass: System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnChangeCSS_Click(object sender, EventArgs e)
{
lblMessage.CssClass = "LabelGrey";
}
protected void btnChangeStyle_Click(object sender, EventArgs e)
{
lblWithoutStyle.Text = "Text with Style";
lblWithoutStyle.Style.Add("font-size", "50px");
}

protected void btnWithoutClass_Click(object sender, EventArgs e)


{
lblWithoutClass.Attributes.Add("class", "ClassJoined");
}
}

Output:-
Conclusion:- This program is running successful.

Example-2: Navigate the Web form from one page to theanother by Clicking
on the ImageButton control.

Source code:-
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ImageButton Sample</title>
<script language="C#" runat="server">

void ImageButton_Click(object sender, ImageClickEventArgs e)


{
Label1.Text = "You clicked the ImageButton control at the
coordinates: (" +
e.X.ToString() + ", " + e.Y.ToString() + ")";
}

</script>

</head>

<body>

<form id="form1" runat="server">

<h3>ImageButton Sample</h3>
Click anywhere on the image.<br /><br />

<asp:ImageButton id="imagebutton1" runat="server"


AlternateText="ImageButton 1"
ImageAlign="left"
ImageUrl="images/pict.jpg"
OnClick="ImageButton_Click"/>

<br /><br />

<asp:label id="Label1" runat="server"/>

</form>

</body>
</html>

Output:-

Conclusion:- This program is running successful.


Practical-3:Create a web application to demonstrate various server-side states
of ASP.NET Pages.

Example-1:Demonstrate the use of client-side states in ASP.NET.(View


state,Control state,Hidden Field state).(IT Lab)

Source code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"


Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
<title>
Untitled Page
</title>
</head>

<body>
<form id="form1" runat="server">
<div>
&nbsp; &nbsp; &nbsp;

<table style="width: 568px; height: 103px">

<tr>
<td style="width: 209px">
<asp:Label ID="lblstr" runat="server" Text="Enter a String"
style="width:94px">
</asp:Label>
</td>

<td style="width: 317px">


<asp:TextBox ID="txtstr" runat="server" style="width:227px">
</asp:TextBox>
</td>
</tr>

<tr>
<td style="width: 209px"> </td>
<td style="width: 317px"> </td>
</tr>

<tr>
<td style="width: 209px">
<asp:Button ID="btnnrm" runat="server"
Text="No action button" style="width:128px" />
</td>

<td style="width: 317px">


<asp:Button ID="btnstr" runat="server"
OnClick="btnstr_Click" Text="Submit the String" />
</td>
</tr>
<tr>
<td style="width: 209px"> </td>

<td style="width: 317px"> </td>


</tr>

<tr>
<td style="width: 209px">
<asp:Label ID="lblsession" runat="server" style="width:231px" >
</asp:Label>
</td>

<td style="width: 317px"> </td>


</tr>

<tr>
<td style="width: 209px">
<asp:Label ID="lblshstr" runat="server">
</asp:Label>
</td>

<td style="width: 317px"> </td>


</tr>

</table>

</div>
</form>
</body>
</html>

Output:-
Conclusion:- This program is running successful.

Example-2: Create a application of Login form accepting Username and


Password of User stores values in Cookie.If user is valid then switch the user to
next page and display Login Successful Message on screen.(HOMEWORK)
using SendGrid;
using System.Net;
using System.Configuration;
using System.Diagnostics;

public class EmailService : IIdentityMessageService

{
public async Task SendAsync(IdentityMessage message)
{
await configSendGridasync(message);
}

// Use NuGet to install SendGrid (Basic C# client lib)


private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress(
"[email protected]", "Royce Sellars (Contoso Admin)");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;

var credentials = new NetworkCredential(


ConfigurationManager.AppSettings["emailServiceUserName"],
ConfigurationManager.AppSettings["emailServicePassword"]
);

// Create a Web transport for sending email.


var transportWeb = new Web(credentials);

// Send the email.


if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
Trace.TraceError("Failed to create Web transport.");
await Task.FromResult(0);
}
}
}
Output:-

Conclusion:- This program is running successful.

You might also like