TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tangara G
NA
298
94k
Dun understand why need to name the Session = something
Dec 26 2016 5:53 AM
Hi experts,
I refer to the below code. Can someone explain to me why we need to name the Session = something ?
Specifically, this part :
if
(!IsPostBack)
{
if
(Session[
"FirstName"
] == null && Session[
"LastName"
]==null)
{
Session[
"FirstName"
] =
"Aspdotnet"
;
Session[
"LastName"
] =
" Suresh"
;
lblString.Text =
"Welcome "
+ Session[
"FirstName"
] + Session[
"LastName"
];
}
And here's the full code
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"SessionForm4.aspx.cs"
Inherits=
"hiddenfieldtest.SessionForm4"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<h3>SessionStateData.aspx</h3>
<table>
<tr>
<td>FirstName:</td><td><asp:TextBox ID=
"txtfName"
runat=
"server"
/></td>
</tr>
<tr>
<td>LastName:</td><td><asp:TextBox ID=
"txtlName"
runat=
"server"
/></td>
</tr>
<tr><td></td><td> <asp:Button ID=
"btnSubmit"
runat=
"server"
Text=
"Set SessionState Data"
OnClick=
"btnSubmit_Click"
/></td></tr>
</table>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
namespace
hiddenfieldtest
{
public
partial
class
SessionForm4 : System.Web.UI.Page
{
protected
void
Page_Load(object sender, EventArgs e)
{
}
// Set Session values during button click
protected
void
btnSubmit_Click(object sender, EventArgs e)
{
Session[
"FirstName"
] = txtfName.Text;
Session[
"LastName"
] = txtlName.Text;
Response.Redirect(
"Default2.aspx"
);
}
}
}
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"Default2.aspx.cs"
Inherits=
"hiddenfieldtest.Default2"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<h3>Default2.aspx</h3>
<table>
<tr>
<td colspan=
"2"
>Welcome <b><asp:Label ID=
"lblString"
runat=
"server"
/></b></td>
</tr>
<tr>
<td>Your FirstName: </td><td><b><asp:Label ID=
"lblfName"
runat=
"server"
/></b></td>
</tr>
<tr>
<td>Your LastName </td><td><b><asp:Label ID=
"lbllName"
runat=
"server"
/></b></td>
</tr>
<tr><td></td><td> </td></tr>
</table>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
namespace
hiddenfieldtest
{
public
partial
class
Default2 : System.Web.UI.Page
{
protected
void
Page_Load(object sender, EventArgs e)
{
if
(!IsPostBack)
{
if
(Session[
"FirstName"
] == null && Session[
"LastName"
]==null)
{
Session[
"FirstName"
] =
"Aspdotnet"
;
Session[
"LastName"
] =
" Suresh"
;
lblString.Text =
"Welcome "
+ Session[
"FirstName"
] + Session[
"LastName"
];
}
else
{
lblString.Text = Session[
"FirstName"
]+
" "
+ Session[
"LastName"
];
lblfName.Text = Session[
"FirstName"
].ToString();
lbllName.Text = Session[
"LastName"
].ToString();
}
}
}
}
}
Reply
Answers (
9
)
Pay Pal IPN warning message?
How to validate number in asending order in datatable column