2

I cant seem to pass my variable through to the next page. Can anyone tell me what i am doing wrong?

var finalValue = value * sqlCouponValue;
finalValue = Math.Round(finalValue, 2);
Session["discountedOrderTotal"] = finalValue.ToString();

where i am trying to call it again on the next page:

e.Row.Cells[4].Text = "$" + Session["discountOrderTotal"];

Does anyone have any ideas? I have never used session variables before and am not sure why it is just returning a $. Any help would be much appreciated. Thanks!

2
  • 1
    What's going wrong? Is there an error? Perhaps you need a cast, i.e.: "$" + (string)Session["discountOrderTotal"] Commented Jul 8, 2014 at 19:30
  • You might want to take a look at using facade to help avoid this and other issues with Session state management Commented Jul 8, 2014 at 19:36

5 Answers 5

10

you have different names. discountedOrderTotal vs discountOrderTotal

Sign up to request clarification or add additional context in comments.

3 Comments

happens to the best of us
i prefer to persist a class object to a session variable, that way i can utilize strongly typed properties.
Sometimes it just takes an extra set of eyes. Make sure you're taking regular breaks, even if its just 5 minutes every 15-20 or so to refocus your eyes.
0

The first thing you should be careful is the name of the session. It should be same and when you are retrieving the session then you need to specify the type because it returns an object. So try this when you call this to next page

e.Row.Cells[4].Text = "$" + Session["discountedOrderTotal"].ToString();

Comments

0
public partial class Approve : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = Convert.ToString(Session["id"]);
        Label3.Text = Convert.ToString(Session["name"]);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        int id1=Convert.ToInt32(Session["id"]);
        TransferDAL dalob = new TransferDAL();
        int x = dalob.updateapprove(id1);

        Response.Redirect("View.aspx");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        int id1 = Convert.ToInt32(Session["id"]);
        TransferDAL dalob = new TransferDAL();
        int r = dalob.updatereject(id1);
        Response.Redirect("View.aspx");
    }
}

Comments

0
public partial class View : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            List<TransferBO> List2 = new List<TransferBO>();
            TransferDAL obj1 = new TransferDAL();
            List2 = obj1.view();
            Gridview1.DataSource = List2;
            Gridview1.DataBind();



        }

    }

    protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow SelectedRow = Gridview1.SelectedRow;
        Label id1 = (Label)SelectedRow.FindControl("Label1") as Label;
        int id2 = Convert.ToInt32(id1.Text);
        Label id3 = (Label)SelectedRow.FindControl("Label3") as Label;
        string id4 = Convert.ToString(id3.Text);
        Session["id"] = id2;
        Session["name"] = id4;
        Response.Redirect("Approve.aspx");



    }
}

Comments

0
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Table ID="Table1" runat="server">
        <asp:TableRow>
            <asp:TableCell>Transfer Request ID</asp:TableCell>
                           <asp:TableCell>  <asp:Label ID="Label1" runat="server" Text='<%# Eval("TransferRequestId") %>'></asp:Label></asp:TableCell>
                           <asp:TableCell></asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
             <asp:TableCell>Employee Name</asp:TableCell>
                           <asp:TableCell>  <asp:Label ID="Label3" runat="server" Text='<%# Eval("EmployeeName") %>'></asp:Label></asp:TableCell>
                           <asp:TableCell></asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>
            <asp:TableCell><asp:Button ID="Button1" runat="server" Value="APPROVE" Text="Approve" OnClick="Button1_Click"></asp:Button></asp:TableCell>

            <asp:TableCell><asp:Button ID="Button2" runat="server" value="REJECT" Text="Reject" Onclick="Button2_Click"></asp:Button></asp:TableCell>
        </asp:TableRow>
    </asp:Table>

</asp:Content>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.