0

Hello,

I am writing a prog with ASP in C#.
I have 2 separate pages.
on the first page there are 2 textboxes and a button.
the first box is a validation check (a code)
the second one is the ammount of money you want to withdraw (max of 1000)
if I test it, it works. when I type the correct code and an ammount thats Lower than 1000. it will print my current credit in the next page. (type 200 in the second textbox and the next page will say: Current Credit: 800).
However when I press the back button on that screen it will reset the value to 1000 instead of keeping it 800
My actual question is. how do I send an Int trough a session instead of a string?
If I know that I can make a new int that has a value of 0 and when it runs trough the next page it will change to 1 and I can create an if-else about the total ammount of money. since strings are static and not able to change I cannot do it that way.

sorry for the long text to explain something simple.

This is my current code, which do not work:

FIRST PAGE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Opdracht5
{
    
    public partial class _Default : System.Web.UI.Page
    {

        int totaal;
        int saldo;
        string invoer1;
        string invoer2;
        int bedrag;
        string resultaat;
        int hulpint;
        

        protected void Page_Load(object sender, EventArgs e)
        {
            
  
        }
        
        protected void Button1_Click(object sender, EventArgs e)
        {

            Application.Add("hulpint", "" + hulpint);
            
           

            if (hulpint.Equals("1"))
            {
                goto spring;
            }
            else
            {
                totaal = 1000;
            }
            
            spring:
            Application.Add("totaal", "" + totaal);
            Application.Add("saldo", "" + saldo);
            invoer1 = TextBox1.Text;
            invoer2 = TextBox2.Text;
            bedrag = Int32.Parse(invoer2);
            resultaat = Convert.ToString(saldo = totaal - bedrag);
            Session.Add("resultaat", "" + resultaat);
            

            if (invoer1.Equals("1234"))
            {
                if (bedrag < saldo && bedrag > 0)
                {
                    Response.Redirect("WebForm1.aspx");
                }
                else
                {
                    Response.Redirect("foutiefbedrag.aspx");
                }
            }
            else
            {
                Response.Redirect("foutepincode.aspx");
            }  
        }
    }
}

SECOND PAGE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Opdracht5
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        
        

        protected void Page_Load(object sender, EventArgs e)
        {
            
            string resultaat = Session["resultaat"].ToString(); 
            Response.Write("NIEUW SALDO: € " + resultaat);
            
            string hulpint = Application["hulpint"].ToString();
            
            hulpint.Equals("1");
            
            
            
        }
        protected void BackButton3_Click(object sender, EventArgs e)
        {
            
            Response.Redirect("Default.aspx");
            
        }
    }
}
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Robert955
0

Create a get;set; modifier and access to in from both classes.

//main form:
public static intSaldo { get; set; }

//set it on a button click:
intSaldo = int.Parse(textBoxSaldo.Text);

//read it when you want (when comming back to main form):
private void ReadSaldo()
{
    int _saldo = intSaldo;
    //do with it what ever you want!
    //and intSaldo is also available in the whole class - its global variable (and in other classes too!
}

//on form2:
void GetSaldo()
{
   //access to saldo on main form:
   int saldo = MainForm.intSaldo;
}

If this is not it, please go ahead and ask for more.

0

session value always taking as a string...you can convert session value in Int whenever you need or in next page

0

session value always taking as a string...you can convert session value in Int whenever you need or in next page

How do I do that?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.