[description]session creation in asp.net[/description]
session creation in asp.neti want to creat a session in asp.net
Page 1 of 1
3 Replies - 7008 Views - Last Post: 07 November 2008 - 04:37 AM
Replies To: session creation in asp.net
#2
Re: session creation in asp.net
Posted 05 November 2008 - 11:17 PM
#4
Re: session creation in asp.net
Posted 07 November 2008 - 04:37 AM
1.Define an ASP.NET web site.
2. Create two pages within the site. The first page will contain an ASP.NET Web Form that will post back to itself and then redirect to the second page.
Note: The reason this example uses two pages is to prove that a session variable is available to a second, third, fourth, etc. page in the web site. Request variables, which are an alternative to session variables, cannot be carried over from an ASP.NET Web Form on one page to a second page
3. The first page must contain an ASP.NET Web Form that contains one <asp:textbox> server control and an <asp:button> server control. The "id" attribute of the textbox control should be set to "txtFirstName". The full code for the first page is provided below. Choose either C# or VB, depending on which language you've chosen for your ASP.NET site:
This code pulls the contents from the <asp:textbox> server control named "txtFirstName" and creates a session variable named"sessFirstName" which is set equal to the contents of the server control. In other words, this code creates a session variable that holds the information the user enters on the form page.
In the first Page
In the second page
2. Create two pages within the site. The first page will contain an ASP.NET Web Form that will post back to itself and then redirect to the second page.
Note: The reason this example uses two pages is to prove that a session variable is available to a second, third, fourth, etc. page in the web site. Request variables, which are an alternative to session variables, cannot be carried over from an ASP.NET Web Form on one page to a second page
3. The first page must contain an ASP.NET Web Form that contains one <asp:textbox> server control and an <asp:button> server control. The "id" attribute of the textbox control should be set to "txtFirstName". The full code for the first page is provided below. Choose either C# or VB, depending on which language you've chosen for your ASP.NET site:
This code pulls the contents from the <asp:textbox> server control named "txtFirstName" and creates a session variable named"sessFirstName" which is set equal to the contents of the server control. In other words, this code creates a session variable that holds the information the user enters on the form page.
In the first Page
<%@ Page Language="C#" %><script language="C#" runat="server">
void Button1_Click(object sender, EventArgs e)
{
Session["sessFirstName"] = Request["txtFirstName"];
Response.Redirect("session2.aspx");
}</script><html><head><title>Session Page 1</title></head><body>
ASP.NET C# session variable and web form example - page 1<form id="Form1" method="post" runat="server"><p>first name:<asp:TextBox id="txtFirstName" runat="server" /></p><p><asp:Button id="Button1" runat="server" Text="Submit" onclick="Button1_Click" /></p></form></body></html>
In the second page
<%@ Page Language="C#" %><html><head><title>Session Page 2</title></head><body><p>ASP.NET C# session variable and web form example - page 2</p><p>first name: <%=Session["sessFirstName"]%></p></body></html>
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|