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

Net Pract 1-4

The document contains code examples for 4 practical programs in ASP.NET: 1. A program to check if a query string is empty. 2. A program to change the color of a label text control programmatically. 3. A program to enable and disable a textbox and change its width programmatically. 4. A program to increase and decrease font size programmatically. For each program, the code provided includes the ASP.NET markup, C# codebehind, and examples of the output.

Uploaded by

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

Net Pract 1-4

The document contains code examples for 4 practical programs in ASP.NET: 1. A program to check if a query string is empty. 2. A program to change the color of a label text control programmatically. 3. A program to enable and disable a textbox and change its width programmatically. 4. A program to increase and decrease font size programmatically. For each program, the code provided includes the ASP.NET markup, C# codebehind, and examples of the output.

Uploaded by

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

Practical No.

Aim: Write a program to check whether empty Query String is entered in Asp.net

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FirstPage.aspx.cs"


Inherits="QueryStrng.FirstPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>First Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="textLBL" runat="server" Text="Enter Any Text "></asp:Label>
<asp:TextBox ID="txtTB" runat="server"></asp:TextBox>
<br />
<asp:Button ID="sendBTN" runat="server" OnClick="sendBTN_Click" Text="Send" />
</form>
</body>
</html>

using System;
namespace QueryStrng
{
public partial class FirstPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { }
protected void sendBTN_Click(object sender, EventArgs e)
{
Response.Redirect("SecondPage.aspx?name=" + txtTB.Text.Trim());
}
}

}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SecondPage.aspx.cs"
Inherits="QueryStrng.SecondPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="txtLBL2" runat="server"></asp:Label>
</form>
</body>
</html>

SecondPage.aspx.cs

using System;
namespace QueryStrng{
public partial class SecondPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Request.QueryString["name"].ToString()))
txtLBL2.Text = "QueryString is empty !!"; else
{
string str = Request.QueryString["name"].ToString();
txtLBL2.Text = "QueryString is not empty and value is " + str.ToString();
}
}
}
}
Output:-

Case 1:

Case 2:

:
Practical No.2

Aim: Write a program to change the color of label text control programmatically in Asp.net

Code:

< %@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextColor.aspx.cs"


Inherits="TextColor.TextColor" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Second Page</title>
</head>
<body>
<form id="form1" runat="server">
<table><tr><td rowspan="2">
<asp:Label ID="inputLBL" runat="server" Text="Enter The Text "></asp:Label>
&nbsp;&nbsp;
<asp:TextBox ID="txtTB" runat="server" Height="30px" Width="210px"></asp:TextBox>
<br />
Chosse the color for the bove Text<asp:RadioButtonList ID="listRBTN" runat="server">
<asp:ListItem Selected="True">Black</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Orange</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="viewBTN" runat="server" OnClick="viewBTN_Click" Text="View
The Text" />
</td>
<td valign="bottom">Output : </td></tr>
<tr><td valign="top">
<asp:Label ID="outputLBL" Text=" " runat="server"></asp:Label>
</td></tr></table>
</form>
</body>
</html>
using System;
namespace TextColor
{
public partial class TextColor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { }
protected void viewBTN_Click(object sender, EventArgs e)
{
int a = listRBTN.SelectedIndex;
switch (a)
{
case 0: outputLBL.ForeColor = System.Drawing.Color.Black; break;
case 1: outputLBL.ForeColor = System.Drawing.Color.Red; break;
case 2: outputLBL.ForeColor = System.Drawing.Color.Green; break;
case 3: outputLBL.ForeColor = System.Drawing.Color.Blue; break;
case 4: outputLBL.ForeColor = System.Drawing.Color.Yellow; break;
case 5: outputLBL.ForeColor = System.Drawing.Color.Orange; break;
}
outputLBL.Text = txtTB.Text;
}
}
}
OUTPUT:-
Practical No.3

Aim: Write a program to Enable-Disable Textbox and also change width of Textbox
programmatically in Asp.net

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TBcontrol.aspx.cs"


Inherits="WebApplication2.TBcontrol" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Homepage</title>
</head>
<body>
<form id="form1" runat="server">
Enter the required width of the given TextBox
<asp:TextBox ID="inputTB" runat="server"></asp:TextBox>
<asp:Label ID="txtLBL" runat="server" Text=""></asp:Label>
<br />
<asp:RadioButton ID="enableRBTN" runat="server" Checked="True"
GroupName="RBTN" OnCheckedChanged="enableRBTN_CheckedChanged" Text="Enable" />
<br />
<asp:RadioButton ID="disableRBTN" runat="server" GroupName="RBTN"
Text="Disable" OnCheckedChanged="disableRBTN_CheckedChanged" />
<br />
<asp:Button ID="modifyBTN" runat="server" OnClick="modifyBTN_Click"
Text="Modify the Width" />
</form>
</body>
</html>
using System; namespace
WebApplication2
{ public partial class TBcontrol :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { } protected
void enableRBTN_CheckedChanged(object sender, EventArgs e)
{
inputTB.Enabled = true;
}
protected void disableRBTN_CheckedChanged(object sender, EventArgs e)
{
inputTB.Enabled = false;
}
protected void modifyBTN_Click(object sender, EventArgs e)
{
if (enableRBTN.Checked)
{
txtLBL.Text = ""; inputTB.Width =
Convert.ToInt32(inputTB.Text);
}
else
txtLBL.Text = "TextBox is disabled !!";
}
}
}
Output:-

Case 1:

Case 2:
Practical No.4

Aim: Write a program to increase and decrease font size programmatically in Asp.net

Code:

< %@ Page Language="C#" AutoEventWireup="true" CodeBehind="IncDecPage.aspx.cs"


Inherits="IncDecText.IncDecPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>HomePage</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td colspan="2">
<asp:Label ID="textLBL" runat="server" Width="500px" text="Web Development"
FontSize="10"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="incBTN" runat="server" Text="Increace Text Size"
OnClick="incBTN_Click" />
</td>
<td align="center">
<asp:Button ID="decBTN" runat="server" Text="Decrease Text Size"
OnClick="decBTN_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
using System;
namespace IncDecText
{ public partial class IncDecPage :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { }
protected void incBTN_Click(object sender, EventArgs e)
{
int curntSize = Convert.ToInt32(textLBL.Font.Size.ToString().Replace("pt", ""));
textLBL.Font.Size = curntSize + 1;
}
protected void decBTN_Click(object sender, EventArgs e)
{
int curntSize = Convert.ToInt32(textLBL.Font.Size.ToString().Replace("pt", ""));
textLBL.Font.Size = curntSize - 1;
}
}
}
Output:-

Case 1:

Case 2:
Index

S.no. Name of the Programs Page Number Date Remarks

Program to check whether


1. empty Query String is entered
in Asp.net
Program to change the color of
2. label text control
programmatically in Asp.net
Program to Enable-Disable
Textbox and also change width
3.
of Textbox programmatically in
Asp.net
Program to increase and
4. decrease font size
programmatically in Asp.net

C# code to display the asterisk


5.
pattern

C# code to prompt a user to


input his/her name and country
name and then the output will
6.
be shown as an example below:
E.g.: Hello Ram from country
India!
C# code to convert

Decimal to Binary
7.
• Decimal to Octal
• Decimal to
Hexadecimal

C# code to convert infix into


8.
postfix notation.

C# code to convert digits to


9
words.
C# code to convert following
10. currency conversion. Rupees to
dollar, frank, euro.
C# code to convert Celsius to
11. Fahrenheit and Fahrenheit to
Celsius

You might also like