Asp DHARMM

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-1. Create a web page with following controls and display inputted/selected
values: Label, Text Box, Radio Button, Radio Button List, Checkbox, Check
boxlist, Calendar, Drop Down List, List box and File Upload Control.

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

<head id="Head1" runat="server">


<title>ASP.NET Controls Example</title>

</head>

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

<div>
<!-- Label and TextBox -->

<asp:Label ID="Label1" runat="server" Text="Enter your name: "></asp:Label>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<br /><br />

<!-- RadioButton -->

<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Gender" Text="Male" />

<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Gender" Text="Female" />


<br /><br />

<!-- RadioButtonList -->


<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>

<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>

<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>


</asp:RadioButtonList>

<br /><br />

ASP.NET 1
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

<!-- Checkbox -->

<asp:CheckBox ID="CheckBox1" runat="server" Text="Subscribe to newsletter" />


<br /><br />

<!-- CheckboxList -->

<asp:CheckBoxList ID="CheckBoxList1" runat="server">

<asp:ListItem Text="Item 1" Value="1"></asp:ListItem>

<asp:ListItem Text="Item 2" Value="2"></asp:ListItem>

<asp:ListItem Text="Item 3" Value="3"></asp:ListItem>


</asp:CheckBoxList>
<br /><br />

<!-- Calendar -->

<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>


<br /><br />

<!-- DropDownList -->


<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem Text="Select an item" Value=""></asp:ListItem>


<asp:ListItem Text="Item A" Value="A"></asp:ListItem>

<asp:ListItem Text="Item B" Value="B"></asp:ListItem>


<asp:ListItem Text="Item C" Value="C"></asp:ListItem>
</asp:DropDownList>

<br /><br />

<!-- ListBox -->


<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">

<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>

ASP.NET 2
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
</asp:ListBox>
<br /><br />

<!-- FileUpload -->

<asp:FileUpload ID="FileUpload1" runat="server" />

<br /><br />

<!-- Button to submit form -->


<asp:Button ID="Button1" runat="server" Text="Submit" />

</div>

<!-- Label to display results -->

<div>
<asp:Label ID="ResultLabel" runat="server" Text=""></asp:Label>

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

</html>
OUTPUT:

ASP.NET 3
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-2. Use session, query string, view state, cookies and application variable
using appropriate examples (Set and Get) Hint: Design Login form.

Partial Class session


Inherits System.Web.UI.Page

ASP.NET 4
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Session("uname") =
TextBox1.Text

Session("pass") = TextBox2.Text Response.Redirect("home.aspx") End


Sub End Class

Query string:

Partial Class QueryString Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Response.Redirect("home1.aspx?uname=" + TextBox1.Text + "&pass=" + TextBox2.Text)
End Sub End Class

View state:
Partial Class viewState

Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If ViewState("c1") Is
Nothing Then
ViewState("c1") = 0 Else
ViewState("c1") += 1 End If

ASP.NET 5
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA
Label1.Text = ViewState("c1") End Sub End
Class

Cookies:
Partial Class cookies
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Cookies("c1")("uname") = TextBox1.Text Response.Cookies("c1")("pass")
= TextBox2.Text
Response.Cookies("c1").Expires = Date.Now.AddSeconds(30)
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Label1.Text
= Request.Cookies("c1")("uname")
Label2.Text = Request.Cookies("c1")("pass") End
Sub
End Class

Application:
Partial Class application Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If Application("c1")
Is Nothing Then
Application("c1") = 0 Else
Application("c1") += 1 End If

Label1.Text = Application("c1")
End Sub

End Class

ASP.NET 6
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-3. Develop a web form for Cricket Player entry (Only HTML/ASPX Code)
using appropriate master page, header, footer and data base table.
[Hint:Player_Master (P_Id, P_Name, P_Password, P_Gender, P_ContactNo,
P_Email, P_Address, P_RegDate, P_Type)].

Master page Header Footer:


<%@ Master Language="vb" AutoEventWireup="true" %>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>Cricket Player Registration</title>

<link href="site.css" rel="stylesheet" type="text/css" />


</head>
<body>

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

<header class="header">
<div class="container">
<h1>Cricket Club</h1>

<nav>
<ul>
<li><a href="Home.aspx">Home</a></li>
<li><a href="Regi.aspx">Registration</a></li>

<li><a href="Contact.aspx">Contact Us</a></li>

</ul>

ASP.NET 7
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA
</nav>
</div>

</header>
<div class="content">

<asp:ContentPlaceHolder id="MainContent" runat="server" >

<p>
<br />
</p>

</asp:ContentPlaceHolder>

</div>

<footer class="footer"> <div

class="container">
<p>&copy; 2024 Cricket Club. All rights reserved.</p>

<p>123 Cricket Street, Cricketville, CR1 2AB</p>

</div>
</footer>

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

OUTPUT:

ASP.NET 8
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

DataBase:
CREATE TABLE [dbo].[Player_Master] (

[P_Id] INT IDENTITY (1, 1) NOT NULL, [P_name] NVARCHAR (50) NULL,

[P_password] NVARCHAR (50) NULL, [P_gender] NVARCHAR (50) NULL,

[P_contactno] NUMERIC (18) NULL, [P_emailid] NVARCHAR (50) NULL, [P_address] NVARCHAR (50) NULL,
[P_regdate] NVARCHAR (50) NULL, [P_type] NVARCHAR (50) NULL, PRIMARY KEY CLUSTERED ([P_Id] ASC)

);

ASP.NET 9
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-4. Apply validations in the form developed in the above Question No. 3.

<%@ Page Title="" Language="vb" MasterPageFile="~/Site.master" %>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<table style="width: 100%">
<tr>
<td style="width: 254px">&nbsp;</td>
<td style="font-size: xx-large; text-decoration: underline; text-align: left"><strong>Player Registration
</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Player Name:</td>
<td>
<asp:TextBox ID="txt_pname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_pname" ErrorMessage="*Enter PlayerName" ForeColor="Red">*Enter
PlayerName</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Password:</td>
<td>
<asp:TextBox ID="txt_pass" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txt_pass" ErrorMessage="*Enter Password" ForeColor="Red">*Enter
Password</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Gender:</td>
<td>
<asp:TextBox ID="txt_gen" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"

ASP.NET 10
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

ControlToValidate="txt_gen" ErrorMessage="*Enter Gender" ForeColor="Red">*Enter


Gender</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txt_contact" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txt_contact" ErrorMessage="*Enter ContactNo" ForeColor="Red">*Enter
ContactNo</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Email ID:</td>
<td>
<asp:TextBox ID="txt_email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txt_email" ErrorMessage="*Enter Email" ForeColor="Red">*Enter
Email</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txt_email" ErrorMessage="*Enter Valid Email" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*Enter Valid
Email</asp:RegularExpressionValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Address:</td>
<td>
<asp:TextBox ID="txt_address" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txt_address" ErrorMessage="*Enter Address" ForeColor="Red">*Enter
Address</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Registration Date:</td>
<td>
<asp:TextBox ID="txt_rdate" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"

ASP.NET 11
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

ControlToValidate="txt_rdate" ErrorMessage="*Enter Registration Date" ForeColor="Red">*Enter


Registration Date</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">Player Type:</td>
<td>
<asp:TextBox ID="txt_ptype" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txt_ptype" ErrorMessage="*Enter Player Type" ForeColor="Red">*Enter Player
Type</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 254px">&nbsp;</td>
<td>
<asp:Button ID="btn_ins" runat="server" Text="Insert" />
</td>
<td>&nbsp;</td>
</tr>
</table>
</asp:Content>

OUTPUT:

ASP.NET 12
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-5. Develop code for insert, update, search and delete facilities using form
developed in the above Question No. 3 using GridView Control or any other
control.

Imports System.Data.SqlClient Partial Class _Default


Inherits System.Web.UI.Page

ASP.NET 13
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Dim cn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\BCA5\CLG\505


ASP\Journal\WebSite1\App_Data\Database.mdf;Integrated Security=True")

Dim cmd As New SqlCommand Dim qry As String


Dim dr As SqlDataReader

Protected Sub btn_ins_Click(sender As Object, e As EventArgs) Handles btn_ins.Click cn.Open()


qry = "insert into Player_master values('" + txt_pname.Text + "','" + txt_pass.Text + "','" + txt_gen.Text + "'," +
txt_contact.Text + ",'" + txt_email.Text + "','" + txt_address.Text + "','" + txt_rdate.Text + "','" + txt_ptype.Text + "')"
cmd.Connection = cn cmd.CommandText = qry cmd.ExecuteNonQuery() cn.Close()
Response.Redirect("Registration.aspx") End Sub

Protected Sub btn_update_Click(sender As Object, e As EventArgs) Handles btn_update.Click cn.Open()


qry = "update Player_master set P_name='" + txt_pname.Text + "',P_password='" + txt_pass.Text + "',P_gender='"
+ txt_gen.Text + "',P_contactno=" + txt_contact.Text + ",P_emailid='" + txt_email.Text +"',P_address='" +
txt_address.Text + "',P_regdate='" + txt_rdate.Text + "',P_type='" + txt_ptype.Text + "' where P_id=" + txt_id.Text +
""

cmd.CommandText = qry cmd.Connection = cn cmd.ExecuteNonQuery() cn.Close()


Response.Redirect("Registration.aspx") End Sub
Protected Sub btn_del_Click(sender As Object, e As EventArgs) Handles btn_del.Click cn.Open()
qry = "delete from Player_master where P_id=" + txt_id.Text + "" cmd.CommandText = qry

cmd.Connection = cn cmd.ExecuteNonQuery() cn.Close()

Response.Redirect("Registration.aspx") End Sub

Protected Sub btn_search_Click(sender As Object, e As EventArgs) Handles btn_search.Click cn.Open()


qry = "Select * from Player_master where P_id=" + txt_id.Text + "" cmd.Connection = cn

cmd.CommandText = qry dr = cmd.ExecuteReader If (dr.HasRows) Then


Response.Redirect("Registration.aspx")

End If cn.Close() End


Sub End Class

OUTPUT:

ASP.NET 14
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Que-6. Apply exception handling in Question No.3.

Imports System.Data.SqlClient Partial Class _Default

Inherits System.Web.UI.Page

Dim cn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\BCA5\CLG\505


ASP\Journal\WebSite1\App_Data\Database.mdf;Integrated Security=True")

Dim cmd As New SqlCommand Dim qry As String


Dim dr As SqlDataReader
Protected Sub btn_ins_Click(sender As Object, e As EventArgs) Handles btn_ins.Click cn.Open()
qry = "insert into Player_master values('" + txt_pname.Text + "','" + txt_pass.Text + "','" + txt_gen.Text + "'," +
txt_contact.Text + ",'" + txt_email.Text + "','" + txt_address.Text + "','" + txt_rdate.Text + "','" + txt_ptype.Text + "')"

cmd.Connection = cn cmd.CommandText = qry cmd.ExecuteNonQuery() cn.Close()

Catch ex As SqlException lblMessage.Text = "Database error: " & ex.Message Catch


ex As FormatException lblMessage.Text = "Format error: " & ex.Message Catch ex
As Exception lblMessage.Text = "An error occurred: " & ex.Message End Try

Response.Redirect("Registration.aspx") End Sub

Protected Sub btn_update_Click(sender As Object, e As EventArgs) Handles btn_update.Click cn.Open()

qry = "update Player_master set P_name='" + txt_pname.Text + "',P_password='" + txt_pass.Text + "',P_gender='"


+ txt_gen.Text + "',P_contactno=" + txt_contact.Text + ",P_emailid='" + txt_email.Text + "',P_address='" +
txt_address.Text + "',P_regdate='" + txt_rdate.Text + "',P_type='" + txt_ptype.Text + "' where P_id=" + txt_id.Text +
""

ASP.NET 15
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

cmd.CommandText = qry

cmd.Connection = cn
cmd.ExecuteNonQuery()

cn.Close()

Catch ex As SqlException lblMessage.Text = "Database error: " & ex.Message

Catch ex As FormatException lblMessage.Text = "Format error: " & ex.Message

Catch ex As Exception lblMessage.Text = "An error occurred: " & ex.Message End

Try
Response.Redirect("Registration.aspx") End Sub

Protected Sub btn_del_Click(sender As Object, e As EventArgs) Handles btn_del.Click cn.Open()


qry = "delete from Player_master where P_id=" + txt_id.Text + "" cmd.CommandText = qry

cmd.Connection = cn cmd.ExecuteNonQuery() cn.Close() Catch ex As SqlException

lblMessage.Text = "Database error: " & ex.Message Catch ex As FormatException

lblMessage.Text = "Format error: " & ex.Message Catch ex As Exception

lblMessage.Text = "An error occurred: " & ex.Message End Try


Response.Redirect("Registration.aspx") End Sub

Protected Sub btn_search_Click(sender As Object, e As EventArgs) Handles btn_search.Click cn.Open()


qry = "Select * from Player_master where P_id=" + txt_id.Text + "" cmd.Connection = cn cmd.CommandText
= qry dr = cmd.ExecuteReader If (dr.HasRows) Then

Response.Redirect("Registration.aspx")

End If cn.Close() Catch ex As SqlException lblMessage.Text


= "Database error: " & ex.Message Catch ex As

FormatException lblMessage.Text = "Format error: " &


ex.Message Catch ex As Exception lblMessage.Text = "An
error occurred: " & ex.Message End

Try
End Sub End Class

ASP.NET 16
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

OUTPUT:

Que-7. Apply themes in Question No.3.

Skin.skin(File):
<asp:TextBox runat="server" BackColor="Fuchsia" BorderColor="#003300"
BorderStyle="Dotted" BorderWidth="5px" ForeColor="#003300"></asp:TextBox> Web.config:
<pages theme ="skinfile"></pages>
Registration File:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="Registration.aspx.vb" Inherits="_Default" Theme ="SkinFile"%>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">


<table style="width: 100%">
<tr>

<td style="width: 254px">&nbsp;</td>


<td style="font-size: xx-large; text-decoration: underline; text-align: left; width: 444px;"><strong>Player
Registration </strong></td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Player ID</td>

ASP.NET 17
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

<td style="width: 444px">

<asp:TextBox ID="txt_id" runat="server"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Player Name:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_pname" runat="server"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Password:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_pass" runat="server"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Gender:</td>


<td style="width: 444px">

<asp:TextBox ID="txt_gen" runat="server"></asp:TextBox>


</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Contact No:</td>


<td style="width: 444px">

<asp:TextBox ID="txt_contact" runat="server"></asp:TextBox>

ASP.NET 18
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Email ID:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_email" runat="server"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Address:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_address" runat="server"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">Registration Date:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_rdate" runat="server"></asp:TextBox>


</td>

<td>&nbsp;</td>
</tr>

<tr>

<td style="width: 254px">Player Type:</td>

<td style="width: 444px">

<asp:TextBox ID="txt_ptype" runat="server"></asp:TextBox>


</td>

<td>&nbsp;</td>

ASP.NET 19
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

</tr>

<tr>

<td style="width: 254px">&nbsp;</td>

<td style="width: 444px">

<asp:Button ID="btn_ins" runat="server" OnClick="btn_ins_Click" Text="Insert" />


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="btn_update" runat="server" Text="Update" />


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="btn_del" runat="server" Text="Delete" />


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="btn_search" runat="server" Text="Search " />

</td>
<td>&nbsp;</td>

</tr>

<tr>

<td style="width: 254px">&nbsp;</td>

<td style="width: 444px">


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="P_Id"
DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">

<Columns>

<asp:BoundField DataField="P_Id" HeaderText="P_Id" ReadOnly="True" SortExpression="P_Id" />

<asp:BoundField DataField="P_name" HeaderText="P_name" SortExpression="P_name" />

<asp:BoundField DataField="P_password" HeaderText="P_password" SortExpression="P_password" />

<asp:BoundField DataField="P_gender" HeaderText="P_gender" SortExpression="P_gender" />

<asp:BoundField DataField="P_contactno" HeaderText="P_contactno" SortExpression="P_contactno" />

<asp:BoundField DataField="P_emailid" HeaderText="P_emailid" SortExpression="P_emailid" />

<asp:BoundField DataField="P_address" HeaderText="P_address" SortExpression="P_address" />

<asp:BoundField DataField="P_regdate" HeaderText="P_regdate" SortExpression="P_regdate" />

<asp:BoundField DataField="P_type" HeaderText="P_type" SortExpression="P_type" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$

ASP.NET 20
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

ConnectionStrings:DatabaseConnectionString1 %>" DeleteCommand="DELETE FROM [Player_Master] WHERE [P_Id]

= @P_Id" InsertCommand="INSERT INTO [Player_Master] ([P_name], [P_password], [P_gender], [P_contactno],


[P_emailid], [P_address], [P_regdate], [P_type]) VALUES (@P_name, @P_password, @P_gender, @P_contactno,
@P_emailid, @P_address, @P_regdate, @P_type)" ProviderName="<%$
ConnectionStrings:DatabaseConnectionString1.ProviderName %>" SelectCommand="SELECT [P_Id], [P_name],
[P_password], [P_gender], [P_contactno], [P_emailid], [P_address], [P_regdate], [P_type] FROM [Player_Master]"
UpdateCommand="UPDATE [Player_Master] SET [P_name] = @P_name, [P_password] = @P_password, [P_gender] =
@P_gender, [P_contactno] = @P_contactno, [P_emailid] = @P_emailid, [P_address] = @P_address, [P_regdate] =
@P_regdate, [P_type] = @P_type WHERE [P_Id] = @P_Id">

<DeleteParameters>
<asp:Parameter Name="P_Id" Type="Int32" />

</DeleteParameters>

<InsertParameters>

<asp:Parameter Name="P_name" Type="String" />

<asp:Parameter Name="P_password" Type="String" />

<asp:Parameter Name="P_gender" Type="String" />


<asp:Parameter Name="P_contactno" Type="Decimal" />

<asp:Parameter Name="P_emailid" Type="String" />


<asp:Parameter Name="P_address" Type="String" />

<asp:Parameter Name="P_regdate" Type="String" />


<asp:Parameter Name="P_type" Type="String" />

</InsertParameters>

<UpdateParameters>
<asp:Parameter Name="P_name" Type="String" />

<asp:Parameter Name="P_password" Type="String" />


<asp:Parameter Name="P_gender" Type="String" />

<asp:Parameter Name="P_contactno" Type="Decimal" />

<asp:Parameter Name="P_emailid" Type="String" />

<asp:Parameter Name="P_address" Type="String" />

<asp:Parameter Name="P_regdate" Type="String" />

<asp:Parameter Name="P_type" Type="String" />

<asp:Parameter Name="P_Id" Type="Int32" />

</UpdateParameters>

ASP.NET 21
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

</asp:SqlDataSource>

</td>

<td>&nbsp;</td>

</tr>

</table>

</asp:Content>

OUTPUT:

Que-8. Apply proper security in Question No.3.

Password Handling:
Imports System.Security.Cryptography
Imports System.Text
Public Function HashPassword(ByVal password As String) As String
Using sha256 As SHA256 = SHA256.Create()
Dim bytes As Byte() = sha256.ComputeHash(Encoding.UTF8.GetBytes(password))
Return BitConverter.ToString(bytes).Replace("-", "").ToLower() End Using
End Function

ASP.NET 22
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Cross-Site Scripting (XSS) Prevention:

lblMessage.Text = HttpUtility.HtmlEncode(ex.Message)

Use HTTPS:
<system.webServer>
<rewrite>

<rules>

<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">


<match url="(.*)" />

<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />

</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

</rules>
</rewrite>

Security Headers:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block" />
</customHeaders>
</httpProtocol>
</system.webServer>

Error Handling:

ASP.NET 23
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

<system.web>
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
<error statusCode="404" redirect="NotFound.aspx" />
<error statusCode="500" redirect="ServerError.aspx" />
</customErrors>
</system.web>

Cross-Site Request Forgery (CSRF) Prevention:

HTML:
<asp:HiddenField ID=" RequestVerificationToken" runat="server" Value="<%=
ViewState[" RequestVerificationToken"] %>" />

VB:
Dim token As String = Request.Form(" RequestVerificationToken")
If token Is Nothing OrElse token <> ViewState(" RequestVerificationToken").ToString() Then Throw
New HttpException(403, "CSRF validation failed.")
End If

Que-9. Create and consume a web service to display addition and


subtraction.

MathService.aspx:

<%@ WebService Language="VB" Class="MathService" %>


Imports System.Web.Services
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.ComponentModel.ToolboxItem(False)> _
Public Class MathService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function Add(ByVal a As Integer, ByVal b As Integer) As Integer Return
a+b
End Function

ASP.NET 24
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

<WebMethod()> _
Public Function Subtract(ByVal a As Integer, ByVal b As Integer) As Integer Return
a-b
End Function End
Class

Default.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Math Operations</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber1" runat="server" />
<asp:TextBox ID="txtNumber2" runat="server" />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<asp:Button ID="btnSubtract" runat="server" Text="Subtract" OnClick="btnSubtract_Click" /> <br
/>
<asp:Label ID="lblResult" runat="server" Text="" /> </div>
</form>
</body>
</html>

Default.aspx.vb:
Imports System.Web.UI
Imports YourProject.MathServiceReference ' Adjust namespace as needed
Public Class Default
Inherits System.Web.UI.Page
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs)Try Dim
number1 As Integer = Convert.ToInt32(txtNumber1.Text)
Dim number2 As Integer = Convert.ToInt32(txtNumber2.Text)

Dim service As New MathService() ' Web service proxy Dim


result As Integer = service.Add(number1, number2)
lblResult.Text = "Result: " & result.ToString()
Catch ex As Exception lblResult.Text =
"Error: " & ex.Message End Try End Sub
Protected Sub btnSubtract_Click(ByVal sender As Object, ByVal e As EventArgs) Try

ASP.NET 25
TY BCA - B ROLL NO:2461124 DHARM J JASOLIYA

Dim number1 As Integer = Convert.ToInt32(txtNumber1.Text)


Dim number2 As Integer = Convert.ToInt32(txtNumber2.Text)

Dim service As New MathService() ' Web service proxy Dim


result As Integer = service.Subtract(number1, number2)
lblResult.Text = "Result: " & result.ToString()
Catch ex As Exception lblResult.Text = "Error: "
& ex.Message
End Try
End Sub
End Class

OUTPUT:

ASP.NET 26

You might also like