Transfer data (in the general list) without a ViewState or whatelse session. as?

I have 3 Array X, Y, Risk. I added a generic (listtraining) list. if i press the buttun button run my codes. But I don't want to use Session to transfer data. in winforms I don't need a session. Can List collect data in its memory?

 public partial class _Default : System.Web.UI.Page
    {
        double[] X;
        double[] Y;
        string[] Risk;
        List<KNNAlgorithms.TrainigSet> listtraining;
        protected void Page_Load(object sender, EventArgs e)
        {
            listtraining = new List<KNNAlgorithms.TrainigSet>();
            if (!IsPostBack)
            {


                X = new double[] { 0.08, 0.07, 0.20, 1.00, 0.05, 0.20, 0.17, 0.15, 0.50, 0.10 };
                Y = new double[] { 0.20, 0.07, 0.09, 0.20, 0.06, 0.25, 0.07, 0.55, 0.08, 0.06 };
                Risk = new string[] { "erkek", "erkek", "erkek", "kadın", "erkek", "erkek", "erkek", "kadın", "erkek", "kadın" };

                for (int i = 0; i < X.Length; i++)
                {
                    KNNAlgorithms.TrainigSet tr = new KNNAlgorithms.TrainigSet();

                    tr.X = X[i];
                    tr.Y = Y[i];
                    tr.Risk = Risk[i];
                    listtraining.Add(tr);
                }
                Session.Add("listtraining", listtraining);
                for (int i = 0; i < listtraining.Count; i++)
                {
                    ListBox1.Items.Add(listtraining[i].X.ToString());
                    ListBox2.Items.Add(listtraining[i].Y.ToString());
                    ListBox3.Items.Add(listtraining[i].Risk.ToString());
                }
            }
        }

        protected void btnHesapla_Click(object sender, EventArgs e)
        {
            List<KNNAlgorithms.TrainigSet> listtraining = new List<KNNAlgorithms.TrainigSet>();

            KNNAlgorithms.KNNModel knn = new KNNAlgorithms.KNNModel();
            double x = double.Parse(txtX.Text);
            double y = double.Parse(txtY.Text);
            int k = int.Parse(txtKValue.Text);
            listtraining = (List < KNNAlgorithms.TrainigSet > )Session["listtraining"];
            lblResult.Text = "Üretilen Sonuç:  " + knn.CalculatedDistancesArray(listtraining, x, y, "kadın", "erkek", k);
        }
    }
      

0


a source to share


2 answers


It is necessary to save the list data, where are your parameters on the Internet - session, view, cache. Data stored in any of these environments is actually stored in server memory.

Another option is that you serialize the data to XML or plain text [whichever you prefer] and save it as a file on the server. This is usually not a good approach, but you end up with a lot of files on the file server.



Another option is to serialize the data, store it in a hidden input element on the form, and pass it from page to page where you need it. It will be a little cumbersome to code and process in general.

Best bet i woudl is still recommended as a session variable.

+2


a source


In ASP.Net, storing data on a page during postbacks can be done using session variables, view variables, or hidden fields.

The only way to pass data between pages is to use either a session object, query string, or POST variables. This means that you either need to pass it to the session or reload the list on every page load.



So the answer to your question is no, the list will not be saved in memory after the pages are loaded. I would suggest that you reload the list on every callback if necessary, or store it in the viewstate if you don't want to use a session variable. However, be aware that using the viewstate adds the size of the returned page.

0


a source







All Articles