Monday, March 26, 2012

Session variable details

Good afternoon, I have two pages one is a select movie page the other is a view cart page, the problem is when i select a movie the details do not show up on the view cart page, can someone point me in the right direction please. below is my code;

select movie code;

<%

@dotnet.itags.org.PageLanguage="C#"Debug="true"AutoEventWireup="true"CodeFile="SelectedFilm.cs"Inherits="SelectedFilm "%>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">

<

head>

<

metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/>

<

metaname="description"content="Description of your web page goes here."/>

<

metaname="keywords"content="Keywords for you web page go here. Each keyword or group of keyword phrases are separated by a comma. Keep this keyword list short and relevant to the content of this specific page and also relevant to the tile of the specific page."/>

<

title>Movie Stream</title>

<

linkrel="shortcut icon"href="shortcut.jpg"/>

<

linkhref="moviestream.css"rel="stylesheet"type="text/css"/>

<

scriptlanguage="javascript"type="text/javascript">

</

script>

</

head>

<

bodystyle="background-color: #dcdcdc"><formid="form1"runat="server">

<

divid="mainnav-container"><divid="mainnav"><divclass="none"><ahref="#maincontent"></a> </div><ul><li><ahref="layout.aspx"title=""><spanstyle="font-size: 11pt">Home</span></a><spanstyle="font-size: 11pt"> </span></li><li><ahref="#"title=""><spanstyle="font-size: 11pt">Contact</span></a></li><li><ahref="MS_Admin.aspx"title=""><spanstyle="font-size: 11pt">Admin Login</span></a><spanstyle="font-size: 11pt">

<%

-- <li><a href="http://links.10026.com/?link=MS_Admin.aspx" title=""><span style="font-size: 11pt">Admin Login</span></a><span style="font-size: 11pt">

--

%></span></li></ul></div><divid="mainnav-side"><ul><li><ahref="registered_customer.aspx"title=""><spanstyle="font-size: 12pt">Login</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="new_customer.aspx"title=""><spanstyle="font-size: 12pt">Register</span></a></li></ul></div><divclass="clear"></div>

</

div>

<!--

SITE NAME & SLOGAN

-->

<

divid="header">

<

ahref="layout.aspx"title="Site name home page"></a><divid="slogan"><spanstyle="font-family: Trebuchet MS"><spanstyle="font-size: 12pt">

MOVIE STREAM

<br/></span>

"Delivering movies to your desk top"

</span></div>

</

div>

<

divid="breadcrumb-container"><divid="breadcrumb"><ahref="layout.aspx"title="Users will see this text ">Home</a> /<ahref="#"title="Users will see this text">Breadcrumb link</a> / Page Title</div><divid="breadcrumb-side">

Search <asp:TextBoxid="SearchWord"runat="server"></asp:TextBox> <asp:ButtonID="Button1"runat="server"Text="go"OnClick="Button1_onclick"/>

<%

-- <asp:Button /> id="Button1" type="button" value="Go" language="javascript" onclick="Button1_onclick()" />--%><asp:LabelID="lblMessage"runat="server"Text=""></asp:Label><br/> </div><divclass="clear"></div>

</

div>

<!--

CONTENT

-->

<

divid="content-container"style="background-color: #ffffff"><!--

SIDE COLUMN

-->

<divid="content-side"style="left: 1px"><p><spanstyle="font-size: 14pt; font-family: Trebuchet MS; color: gray;">Genre</span></p><ulclass="link-list-vertical"><li><ahref="MS_Action.aspx"title="Movies to give you an Adrenaline rush."><spanstyle="font-size: 12pt">

Action

</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="MS_Anime.aspx"title="Animated movies."><spanstyle="font-size: 12pt">Anime</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Movies to make you laugh."><spanstyle="font-size: 12pt">Comedy</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Strong following movies"><spanstyle="font-size: 12pt">Cult</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Facts or fiction."><spanstyle="font-size: 12pt">Documentary</span></a></li><li><spanstyle="font-size: 12pt"></span></li></ul></div><!--

MAIN COLUMN

-->

<divid="content"style="height: 1%"><aname="maincontent"id="maincontent"></a><h1><spanstyle="font-family: Trebuchet MS"></span></h1><br/><br/>

<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1"OnSelectedIndexChanged="DataList1_SelectedIndexChanged1"><ItemTemplate>

Movie ID:

<asp:LabelID="Movie_IDLabel"runat="server"Text='<%# Eval("Movie_ID") %>'></asp:Label><br/><br/>

Genre Category:

<asp:LabelID="Genre_CategoryLabel"runat="server"Text='<%# Eval("Genre_Category") %>'></asp:Label><br/><br/>

Movie name:

<asp:LabelID="Movie_nameLabel"runat="server"Text='<%# Eval("Movie_name") %>'></asp:Label><br/><br/>

Release date:

<asp:LabelID="Release_dateLabel"runat="server"Text='<%# Eval("Release_date") %>'></asp:Label><br/><br/>

Length:

<asp:LabelID="LengthLabel"runat="server"Text='<%# Eval("Length") %>'></asp:Label><br/><br/>

Synopsis:

<asp:LabelID="SynopsisLabel"runat="server"Text='<%# Eval("Synopsis") %>'></asp:Label><br/><br/>

Starring:

<asp:LabelID="StarringLabel"runat="server"Text='<%# Eval("Starring") %>'></asp:Label><br/><br/>

Director:

<asp:LabelID="DirectorLabel"runat="server"Text='<%# Eval("Director") %>'></asp:Label><br/><br/>

Price:

<asp:LabelID="PriceLabel"runat="server"Text='<%# Eval("Price") %>'></asp:Label><br/><br/>

<asp:ButtonID="addToCartel"runat="server"OnClick="addToCart"Text="Select movie"/><br/></ItemTemplate></asp:DataList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)"><SelectParameters><asp:QueryStringParameterDefaultValue="Movie_name"Name="Movie_name"QueryStringField="Movie_name"Type="String"/></SelectParameters></asp:SqlDataSource>

<!--

FOOTER

-->

<

divid="footer"><p>

Movie Stream

</p><p>

382 Brent Cross Road.

</p><p>

? 2007 Movie Stream. All rights reserved.

</p>

</

div></div><!--

SIDE 2 COLUMN

-->

<divid="content-side-2"><divclass="listbox"><divclass="header"><spanstyle="font-size: 12pt; font-family: Trebuchet MS; color: #dcdcdc;"><strongstyle="color: gray">New releases</strong></span></div><olclass="listbox"><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Deja Vu</span></b></a><spanstyle="font-family: Trebuchet MS"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Red Eye</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Dodgers</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Basketball diaries</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li></ol></div></div>

</

div>

</

form>

</

body>

</

html>

<%

-- <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="DataList1_SelectedIndexChanged1">

<ItemTemplate>

Movie ID:

<asp:Label ID="Movie_IDLabel" runat="server" Text='<%# Eval("Movie_ID") %>'></asp:Label><br />

<br />

Genre Category:

<asp:Label ID="Genre_CategoryLabel" runat="server" Text='<%# Eval("Genre_Category") %>'></asp:Label><br />

<br />

Movie name:

<asp:Label ID="Movie_nameLabel" runat="server" Text='<%# Eval("Movie_name") %>'></asp:Label><br />

<br />

Release date:

<asp:Label ID="Release_dateLabel" runat="server" Text='<%# Eval("Release_date") %>'></asp:Label><br />

<br />

Length:

<asp:Label ID="LengthLabel" runat="server" Text='<%# Eval("Length") %>'></asp:Label><br />

<br />

Synopsis:

<asp:Label ID="SynopsisLabel" runat="server" Text='<%# Eval("Synopsis") %>'></asp:Label><br />

<br />

Starring:

<asp:Label ID="StarringLabel" runat="server" Text='<%# Eval("Starring") %>'></asp:Label><br />

<br />

Director:

<asp:Label ID="DirectorLabel" runat="server" Text='<%# Eval("Director") %>'></asp:Label><br />

<br />

Price:

<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label><br />

<br />

<asp:Button ID="addToCartie" runat="server" OnClick="addToCart" Text="Select movie" /><br />

</ItemTemplate>

</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"

SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)">

<SelectParameters>

<asp:QueryStringParameter DefaultValue="Movie_name" Name="Movie_name" QueryStringField="Movie_name"

Type="String" />

</SelectParameters>

</asp:SqlDataSource>--

%>

selectfilm.cs code;

using

System;

using

System.Data;

using

System.Data.SqlClient;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassSelectedFilm : System.Web.UI.Page

{

protectedvoid addToCart(object sender,EventArgs e)

{

if (IsPostBack)

{

Session[

"Movie_IDLabel"] = ("Movie_ID");

Session[

"Movie_nameLabel"] = ("Movie_name");

Session[

"Genre_CategoryLabel"] = ("Genre_Category");

Session[

"Movie_IDLabel"] = ("Movie_ID");

Session[

"Release_dateLabel"] = ("Release_date");

Session[

"LengthLabel"] = ("Length");

Session[

"SynopsisLabel"] = ("Synopsis");

Session[

"StarringLabel"] = ("Starring");

Session[

"DirectorLabel"] = ("Director");

Session[

"PriceLabel"] = ("Price");// Response.Redirect("viewcart.aspx");

}

Response.Redirect(

"viewcart.aspx");

}

And my view cart code;

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="viewcart.aspx.cs"Inherits="viewcart" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server">

<scriptlanguage="javascript"type="text/javascript">

</

script>

</

head>

<

body><formid="Form1"runat="server">

<asp:Labelid="Movie_IDLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="Movie_nameLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="PriceLabel"runat="server"Font-size="30"></asp:Label>

</form>

</

body>

</

html>

viewcart cs code

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Web.Configuration;

using

System.Data.SqlClient;

using

System.Text.RegularExpressions;

public

partialclassviewcart : System.Web.UI.Page

{

void Page_Load(object sender,EventArgs e)

{

Movie_IDLabel.Text =

Convert.ToString(Session["Movie_ID"]);

Movie_nameLabel.Text =

Convert.ToString(Session["Movie_name"]);

PriceLabel.Text =

Convert.ToString(Session["Price"]);

}

Hi, I have not gone through all the code you have up there...but here is how you could do it..

On your first page set the session variables and access them on your second page...

I think you want to access the value of the textbox's or label's value in the second page rather than the name of them..

On first page...

Session["variable1"] = textBox1.value;

On the second page

string str = Session["variable1"];

Where as you are doing as the following..

Session["variable1"] = "Text" // where your text is the name of the control from what i see in the example you gave...


Hi thanks for your response, the problem is im trying to bring up a label and not a textbox, how would i go about doing this. thank you

Is there anyone out there who can help me please.


I believe you are saying that you want to get the "text value" of the label...

If thats right, you could do something like

Session["key1"] = label1.text; // this should be done on Page One

One second page, get the value from session as Session["key1"]

0 comments:

Post a Comment