ASP.NET

1. ASP.NET Introduction 2. Comp of .Net Framework 3.5 3. Sys.Req for VS 2008 4. ASP.NET Envrmnt Setup 5. VS2010 Ultimate Sys.Req 6. Installing VS 2010 7. VS 2012 Sys.Req 8. Installing VS Exp 2012 9. Start the VS 2008 10. Application Life Cycle 11. Page Life Cycle 12. Page Life Cycle Events 13. ASP.NET Example 14. Event Handling 15. Default Events 16. Server Side 17. Request Object 18. Response Object 19. Server Controls 20. Server Controls Properties 21. Server Controls Methods 22. HTML Server Controls 23. Client Side 24. ASP.NET Basic Controls 25. TextBox Control 26. CheckBox Controls 27. RadioButton Controls 28. ListBox Control 29. HyperLink Control 30. Image Control 31. BulletedList Control 32. ASP.NET Directives 33. Implements Directive 34. Master Type Directive 35. Page Directive 36. PreviousPage Type 37. Managing State 38. Control State 39. Cookies 40. Query Strings 41. Server-Side State 42. Session State 43. Validation Controls 44. Required FieldValidator 45. Range Validator 46. Compare Validator 47. RegularExpressionValidator 48. Custom Validator 49. Validation Summary 50. Data Source Control 51. AdRotator Control 52. Calendar Control 53. Calendar Control Example 54. Panel Control 55. Panel Control Example 56. Multi Views Control 57. MultiView & View controls 58. MultiView Control Example 59. FileUpload Control 60. FileUpload Control Eg 61. AJAX Control 62. UpdatePanel control 63. UpdateProgress Control 64. Custom Controls 65. Custom Control Eg 66. Personalization 67. Create Simple Profile 68. ADO.NET 69. ADO.NET Objects 70. DataTable 71. DataRow 72. DataColumn 73. Object Example 74. Error Handling 75. Tracing Errors 76. Debugger 77. Security 78. Authentication 79. Authorization 80. LINQ 81. LINQ Query Operators 82. LINQ Example 83. Caching 84. Data Caching 85. Output Caching 86. Object Caching 87. Web Services 88. Create Web Services Eg 89. Web & Machine.config 90. Settings Schema 91. ASP.NET Deployment 92. XCopy Deployment 93. Web Setup Project 94. ASP Interview Part 1 95. ASP Interview Part 2 96. ASP Interview Part 3 97. ASP Interview Part 4 98. ASP Interview Part 5 99. ASP Interview Part 6
Pr.Pg Next Pg

Session State tutorials

  • ASP.NET provides a session state, which is available as the HttpSessionStateclass, as a method of storing session-specific information that is visible only within the session. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides the ability to persist variable values for the duration of that session.

  • You can store your session-specific values and objects in session state, which is then managed by the server and available to the browser or client device. The ideal data to store in session-state variables is short-lived, sensitive data that is specific to an individual session.

 

Advantages of using session state are:

  • Stores client data separately

  • Data persistence   Data placed in session-state variables can be preserved through Internet Information Services (IIS) restarts and worker-process restarts without losing session data because the data is stored in another process space. Additionally, session-state data can be persisted across multiple processes, such as in a Web farm or a Web garden.

  • Platform scalability   Session state can be used in both multi-computer and multi-process configurations, therefore optimizing scalability scenarios.

  • Simple implementation   The session-state facility is easy to use, familiar to ASP developers, and consistent with other .NET Framework classes.

  • Extensibility   You can customize and extend session state by writing your own session-state provider. Session state data can then be stored in a custom data format in a variety of data storage mechanisms, such as a database, an XML file, or even to a Web service. Session-specific events   Session management events can be raised and used by your application.

 

Disadvantage of using session state are:

  • Performance Overhead   Performance overhead in case of large volumes of data/user, because session data is stored in server memory

 

  • Example: from the below example we have created two pages SessionLogin.aspx page and SessionHome.aspx page

  • The first page SessionLogin .aspx pages have two textboxes and 1 button control. The textbox contains the user input like username and password in the session.after clicking the login button the page is redirected to the SessionHome.aspx pages .that display the Username and Password.

Note: User Name : Jack and Password jack@123

SessionLogin.aspx.cs Code:

 

Following example shows the use of ASP.NET Session State(Server-Side State Management) SessionLogin.aspx.cs file:

Sam Sir

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

span style='line-height:115%'> 

public partial class SessionLogin : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

 

}

protected void btnlogin_Click(object sender, EventArgs e)

{

Session["USERNAME"] = txtusername.Text;

Session["PASSWORD"] = txtpassword.Text;

if (txtusername.Text == "Jack" && txtpassword.Text == "jack@123")

{

Response.Redirect("SessionHome.aspx");

}

else

{

Errormsg.Text = "User Name or Password is incorrect";

}

}

}

 

 

 

SessionLogin.aspx Code:

 

Following example shows the use of ASP.NET Session State(Server-Side State Management):

Sam Sir

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionLogin.aspx.cs" Inherits="SessionLogin" %>

 

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

<style type="text/css">

.style1

{

width: 100%;

}

</style>

</head>

<body>

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

<div>

<table class="style1">

<tr>

<td>

&nbsp;</td>

<td>

Session Management Example<br />

&nbsp;(User Login Page)</td>

</tr>

<tr>

<td align="right">

User Name:</td>

<td>

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

</td>

</tr>

<tr>

<td align="right">

Password:</td>

<td>

<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>

</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td>

<asp:Button ID="btnlogin" runat="server" onclick="btnlogin_Click"

Text="Login" />

&nbsp;<asp:Label ID="Errormsg" runat="server"></asp:Label>

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

Output

 

 

asp.net session state example

 

 

SessionHome.aspx.cs Code:

 

Following example shows the use of ASP.NET Session State (Server-Side State Management):

Sam Sir

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class SessionHome : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

if (Session["USERNAME"] == null && Session["PASSWORD"] == null)

{

Response.Redirect("SessionLogin.aspx");

}

else

{

lbluser.Text = Session["USERNAME"].ToString();

lblusername.Text = Session["USERNAME"].ToString();

lblpassword.Text = Session["PASSWORD"].ToString();

}

}

}

}

 

 

SessionHome.aspx Code:

 

 

Following example shows the use of ASP.NET Session State(Server-Side State Management):

Sam Sir

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionHome.aspx.cs" Inherits="SessionHome" %>

 

<!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>cbtSAM ASP.NET Server-Side State Management Example </title>

<style type="text/css">

.style1

{

width: 100%;

}

</style>

</head>

<body>

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

<table class="style1">

<tr>

<td>

User Home Page<br />

<br />

Welcome .<asp:Label ID="lbluser" runat="server" Text=""></asp:Label>

<br />

<br />

UserName: <asp:Label ID="lblusername" runat="server" Text=""></asp:Label>

<br />

<br />

Password: <asp:Label ID="lblpassword" runat="server" Text=""></asp:Label>

</td>

</tr>

</table>

</form>

</body>

</html>

Output

 

 

asp.net session state example

 

  • Postback: Postback in an event that is triggered when an action is performed by a contol on a asp.net page. for eg. When you click on a button the data on the page is posted back to the server for processing.

  • IsPpstback: Is Postback is normally used on page _load event to detect if the page is getting generated due to postback requested by a control on the page or if the page is getting loaded for the first time.

Pr.Pg border                                              Next Pg