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

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

The document describes two examples of navigating between web pages using different controls in ASP.NET. The first example uses a LinkLabel control to navigate from one page to a URL when clicked. The second example uses an ImageButton control to navigate to another page when clicked, and displays a message in a textbox. Both demonstrate how to handle control click events to perform navigation or other tasks in a web form application.
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)
46 views

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

The document describes two examples of navigating between web pages using different controls in ASP.NET. The first example uses a LinkLabel control to navigate from one page to a URL when clicked. The second example uses an ImageButton control to navigate to another page when clicked, and displays a message in a textbox. Both demonstrate how to handle control click events to perform navigation or other tasks in a web form application.
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

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>&nbsp;</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:-

You might also like