Resolved Emergency - Is the grammar correct? ViewState["ds"] = arr1;

patrick

Well-known member
Joined
Dec 5, 2021
Messages
251
Programming Experience
1-3
Emergency - Is the grammar correct?

I want to add Info structure to ArrayList. My goal is ViewState["ds"] = List;


Please Help Me.

1. Originally, I wanted to add List to ViewState. However, there was a Serialize error.

C#:
        class Info
        {
            public string ORDER_ID { get; set; }
            public string ORDER_STATUS { get; set; }
        }
                List<Info> List1= new List<Info>();
                Info AssignInfo = new Info();     
                for (int i = 0; i < 5; i++)
                {
                         Info.ORDER_ID = "1";
                         Info.ORDER_STATUS = "Complite";
                          List1.Add(Info);
                }
                 ViewState["ds"] = List1;




2. So I tried to add to ViewState by converting List to ArrayList. However, ListArray is not added to ViewState either.
How to add to ViewState ? I need to add Info structure column to ViewState.


C#:
        class Info
        {
            public string ORDER_ID { get; set; }
            public string ORDER_STATUS { get; set; }
        }
                ArrayList arr1 = new ArrayList(4);
                Info Info = new Info();     
                for (int i = 0; i < 5; i++)
                {
                         Info.ORDER_ID = "1";
                         Info.ORDER_STATUS = "Complite";
                          arr1.Add(Info);
                }
                ViewState["ds"] = arr1;
 
Last edited by a moderator:
Try it and see what happens.
 
This means try it out. If you are getting an error report the exact error you are getting. Also post the minimal code to reproduce the problem.
 
This means try it out. If you are getting an error report the exact error you are getting. Also post the minimal code to reproduce the problem.


The error points are the two sources attached at the top.

This is the error name.====>

An error occurred while serializing the value 'UlsanPEWebApp.Pages.PlanMgt.Pln11+Info' in the format 'UlsanPEWebApp.Pages.PlanMgt.Pln11+Info'.

System.ArgumentException: Error serializing value 'UlsanPEWebApp.Pages.PlanMgt.Pln11+Info' of type 'UlsanPEWebApp.Pages.PlanMgt.Pln11+Info'. --->
System.Runtime.Serialization.SerializationException: Type 'UlsanPEWebApp.Pages.PlanMgt.Pln11+Info' in assembly 'UlsanPEWebApp, Version=1.18.1219.2, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
 
OMG! We told you inn the past not to edit posts that have occurred in the past so that it changes the meaning dramatically. This is not Stack Overflow where you keep massaging your original question based on replies and comments. *sigh*
 
UlsanPEWebApp.Pages.PlanMgt.Pln11+Info' in assembly 'UlsanPEWebApp, Version=1.18.1219.2, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
What happens when you mark the class as serializable?
 
 
This means try it out. If you are getting an error report the exact error you are getting. Also post the minimal code to reproduce the problem.

OMG! We told you inn the past not to edit posts that have occurred in the past so that it changes the meaning dramatically. This is not Stack Overflow where you keep massaging your original question based on replies and comments. *sigh*



You were right.

C#:
        [Serializable]
        class Info
        {
            public string ORDER_ID { get; set; }
            public string ORDER_STATUS { get; set; }
        }
                List<Info> List1= new List<Info>();
                Info AssignInfo = new Info();     
                for (int i = 0; i < 5; i++)
                {
                         Info.ORDER_ID = "1";
                         Info.ORDER_STATUS = "Complite";
                          List1.Add(Info);
                }
                 ViewState["ds"] = List1;


[Serializable]
class Info
{
public string ORDER_ID { get; set; }
public string ORDER_STATUS { get; set; }
}


It was solved by adding [Serializable].
 
And to circle back to your original question. The line of code View state["ds"] = arr1; is syntactically correct. It's just a logic error at runtime in your environment trying to do that because the object is not serializable.

It is interesting that you are getting this issue. This would indicate that you have configured IIS to store the view state in a database or some other state handler. If you had IIS configured to use in process memory, there would be no need for serialization.
 

Latest posts

Back
Top Bottom