Last post Aug 27, 2010 04:30 AM by karthicks
Aug 27, 2010 03:40 AM|soulreader7|LINK
in asp.net can i make public objects on my page, for example
public Customer cust1 = new customer();
and use this object on my entire code???
what are the drawbacks of creating public objects??
a single object will be created for all users??? or each user will have a different object????
Aug 27, 2010 04:22 AM|CoskunSUNALI|LINK
Please remember that ASP.NET applications are stateless, meaning that your objects will be disposed as soon as the page lifecycle ends.
You could use "static" objects but please remember that in case IIS recycles your application pool, you will lose the data stored in your static objects.
If you question is only creating a public object in an ASP.NET page and using it through the lifecycle of that page, it is no problem. As long as it is not a "public static" property, it will not be shared across different requests and each visitor will
have its own instance of the public object.
Aug 27, 2010 04:30 AM|karthicks|LINK
it depends on your requirement , if you are going to use the object throughout the page you can create a global object and use it everywhere instead of creating new objects in all the places.
and the object will be created for each and every request of the page, it's not depend on users.