0% found this document useful (0 votes)
54 views26 pages

Asp Neel

Uploaded by

hellohello7678
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)
54 views26 pages

Asp Neel

Uploaded by

hellohello7678
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/ 26

Neel Bhavnagari TY-BCA Roll no:2461179

Asp.Net Journal
Q-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.
Code:
<!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 />

P a g e 1 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<!-- 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:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
P a g e 2 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

</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>

P a g e 3 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

OUTPUT:

P a g e 4 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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

Session:

Partial Class session


Inherits System.Web.UI.Page
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

P a g e 5 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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
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

P a g e 6 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

Application("c1") = 0 Else
Application("c1") += 1 End If
Label1.Text = Application("c1")
End Sub
End Class

Q-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)].

Code:

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>
P a g e 7 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<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>
</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>

P a g e 8 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

OUTPUT:

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)
);

P a g e 9 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

Q-4. Apply validations in the form developed in the above Question No. 3.
Code:
<%@ 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"
ControlToValidate="txt_gen" ErrorMessage="*Enter Gender" ForeColor="Red">*Enter
Gender</asp:RequiredFieldValidator>
P a g e 10 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

</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"
ControlToValidate="txt_rdate" ErrorMessage="*Enter Registration Date" ForeColor="Red">*Enter
Registration Date</asp:RequiredFieldValidator>
</td>
<td>&nbsp;</td>
</tr>

P a g e 11 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<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:

P a g e 12 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

Q-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.
Code:
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()
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

P a g e 13 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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:

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


Code:
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()

P a g e 14 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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 +
""
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()

P a g e 15 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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

OUTPUT:

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


Code:
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>

P a g e 16 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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>

<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>
P a g e 17 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<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>

</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>
P a g e 18 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

</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>

</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" />

P a g e 19 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<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="<%$


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" />

P a g e 20 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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

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

</UpdateParameters>

</asp:SqlDataSource>

</td>

<td>&nbsp;</td>

</tr>

</table>

</asp:Content>

OUTPUT:

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

Code:
Password Handling:
Imports System.Security.Cryptography
Imports System.Text
Public Function HashPassword(ByVal password As String) As String
Using sha256 As SHA256 = SHA256.Create()

P a g e 21 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

Dim bytes As Byte() = sha256.ComputeHash(Encoding.UTF8.GetBytes(password))


Return BitConverter.ToString(bytes).Replace("-", "").ToLower()
End Using
End Function

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>

P a g e 22 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

Error Handling:
<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

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

Code:
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
P a g e 23 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

<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
P a g e 24 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

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:

P a g e 25 | 26
Neel Bhavnagari TY-BCA Roll no:2461179

P a g e 26 | 26

You might also like