Practical no5:-
Aim:-Create Web Form to demonstrate use of the LinkLabel Control for navigating a user from
one page to another page
Source code:-
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
private System.Windows.Forms.LinkLabel linkLabel1;
[STAThread]
static void Main()
Application.Run(new Form1());
public Form1()
// Create the LinkLabel.
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
// Configure the LinkLabel's location.
this.linkLabel1.Location = new System.Drawing.Point(34, 56);
// Specify that the size should be automatically determined by the content.
this.linkLabel1.AutoSize = true;
// Add an event handler to do something when the links are clicked.
this.linkLabel1.LinkClicked += new
System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
// Set the text for the LinkLabel.
this.linkLabel1.Text = "Visit Microsoft";
// Set up how the form should be displayed and add the controls to the form.
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.linkLabel1 });
this.Text = "Simple Link Label Example";
private void linkLabel1_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
// Specify that the link was visited.
this.linkLabel1.LinkVisited = true;
// Navigate to a URL.
System.Diagnostics.Process.Start("http://www.microsoft.com");
}
out put:
Aim:-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.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsControlLibrary1
public partial class UserControl1 : UserControl
private System.Windows.Forms.StatusBar stbMessage;
public delegate void EventHandler(Object sender, EventArgs e);
public event EventHandler SuccessfullyLogin;
public event EventHandler LoginFail;
//Constructor of the class
public UserControl1()
InitializeComponent();
// This is the very simple Login Check Validation
// The Password mus be ... "secret" .....
private bool LoginCheck(string pName, string pPassword)
return pPassword.Equals("secret");
// Validate Login, in any case call the LoginSuccess or
// LoginFailed event, which will notify the Application's
// Event Handlers.
private void button1_Click(object sender, EventArgs e)
// User Name Validation
if (txtnam.Text.Length == 0)
errorpro.SetError(txtnam,"Please enter a user name");
stbMessage.Text = "Please enter a user name";
return;
else
errorpro.SetError(txtnam,"");
stbMessage.Text = "";
// Password Validation
if (txtpw.Text.Length == 0)
errorpro.SetError(txtpw,"Please enter a password");
stbMessage.Text = "Please enter a password";
return;
}
else
errorpro.SetError(txtpw,"");
stbMessage.Text = "";
// Check Password
if (LoginCheck(txtnam.Text, txtpw.Text))
// If there any Subscribers for the LoginSuccess
// Event, notify them ...
if (SuccessfullyLogin != null)
SuccessfullyLogin(this, new System.EventArgs());
else
// If there any Subscribers for the LoginFailed
// Event, notify them ...
if (LoginFail != null)
LoginFail(this, new System.EventArgs());
}
}
// Read-Write Property for User Name Label
public string LabelName
get
return lblname.Text;
set
lblname.Text = value;
// Read-Write Property for User Name Password
public string LabelPassword
get
return lbpwd.Text;
set
lbpwd.Text = value;
}
// Read-Write Property for Login Button Text
public string LoginButtonText
get
return btnlg.Text;
set
btnlg.Text = value;
// Read-Only Property for User Name
[Browsable(false)]
public string UserName
set
txtnam.Text = value;
}
// Read-Only Property for Password
[Browsable(false)]
public string Password {
set
txtpw.Text = value;
Output :-
Example2:-
Aim:-Navigate the Web form from one page to theanother by Clicking on the ImageButton control.
Source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="buttons.aspx.cs" Inherits="
buttons"%>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="z-index: 1; left: 23px; top: 56px; position: absolute" Text="click!" />
<asp:LinkButton ID="LinkButton1" runat="server" EnableTheming="True"
onclick="LinkButton1_Click"
style="z-index: 1; left: 24px; top: 194px; position: absolute"
ToolTip="Link to another page">LinkButton</asp:LinkButton>
<p style="height: 669px">
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/images/smiley-guy.jpg" onclick="ImageButton1_Click"
style="z-index: 1; left: 16px; top: 294px; position: absolute; height: 80px;
width: 88px; right: 1177px; bottom: 421px" />
<asp:TextBox ID="TextBox1" runat="server"
style="z-index: 1; left: 20px; top: 383px; position: absolute"></asp:TextBox>
</p>
<p> </p>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class buttons : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
Button1.Text = "You clicked the button!";
protected void LinkButton1_Click(object sender, EventArgs e)
Response.Redirect("default.aspx");//move to the next link i.e default.aspx
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
TextBox1.Text="keep smiling";
Output:-