Here is the code for the main page (Default.aspx)
<form id="form1" runat="server">
<div style="height: 296px">
<asp:ListBox ID="ListBox1" runat="server" Height="164px" Width="107px"
SelectionMode="Multiple">
<asp:ListItem>Tyres</asp:ListItem>
<asp:ListItem>Battery</asp:ListItem>
<asp:ListItem>Front Glass</asp:ListItem>
<asp:ListItem>Vanity Mirrors</asp:ListItem>
</asp:ListBox>
<br />
<br />
Username:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
EMail:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</div>
</form>
And here is code behind it, (Default.aspx.cs)
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["Item"] != null)
{
ListBox1.SelectedValue = Request.Cookies["Item"].Value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie userCookie = new HttpCookie("UserInfo");
userCookie["userName"] = TextBox1.Text;
userCookie["email"] = TextBox2.Text;
userCookie["items"] = ListBox1.SelectedValue;
//Response.Cookies["Username"].Value =TextBox1.Text;
//Response.Cookies["Email"].Value = TextBox2.Text;
//Response.Cookies["Items"].Value = ListBox1.SelectedValue;
Response.Cookies.Add(userCookie);
Response.Redirect("confirm.aspx");
}
}
I am trying to select all four items, and in the next page I am trying to display the subtotal but error I am getting is it is displaying only first item repeatedly.
Here is the code for next page (confirm.aspx)
<form id="form1" runat="server">
<div style="height: 229px">
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</div>
</form>
and the code for it, (confirm.aspx.cs)
public partial class confirm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["UserInfo"] != null)
{
//TextBox1.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["userName"]);
//TextBox2.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["email"]);
Label1.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["items"]);
Label2.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["items"]);
Label3.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["items"]);
Label4.Text = Server.HtmlEncode(Request.Cookies["UserInfo"]["items"]);
}
}
}
Any suggestion where I might be wrong? The point to note here is, I am total newbie to ASP.NET. One more thing, any tutorials or book from where I can learn ASP.NET better?

New Topic/Question
Reply


MultiQuote



|