Collections
-
Is CObArray and CObList the equivalent of a collection under .NET? I want pass data from one form to the other and then into a control. Can I create a class, add them to the collection, pass it and then fill the control? This in in ASP.NET btw... Thanks Ralph
-
Is CObArray and CObList the equivalent of a collection under .NET? I want pass data from one form to the other and then into a control. Can I create a class, add them to the collection, pass it and then fill the control? This in in ASP.NET btw... Thanks Ralph
ASP.NET is really no different from CGI in the world of HTTP. You can't really send a collection from form to form - you need to use POST data just like form elements in a page. You could store the collection in a session variable, but you'll take big performance hits if you don't clean it up correctly. I'm not really sure what those objects are, but they appear to be an array and a list. Lists are those classes that implement
IList
(and inheritICollection
andIEnumerable
). Arrays implicitly derive fromSystem.Array
, which implementsIList
. So, they're both lists (but you can't use some methods from the aforementioned interfaces with an array - it's still a fixed number of elements). You could serialize this collection and base64-encode it, then make sure it gets sent with your form data to the next page, deserializing it. If you're remaining on the same page (i.e., using post-back), you could also extend thePage
class (your .aspx and code-behind files do this already) and overrideSaveViewState
andLoadViewState
to save this serialized collection, but this only works if using post-back with the same page. You should definitely read the documentation on those two methods - implementing them can be tricky, especially if you don't know what you're doing.Microsoft MVP, Visual C# My Articles
-
ASP.NET is really no different from CGI in the world of HTTP. You can't really send a collection from form to form - you need to use POST data just like form elements in a page. You could store the collection in a session variable, but you'll take big performance hits if you don't clean it up correctly. I'm not really sure what those objects are, but they appear to be an array and a list. Lists are those classes that implement
IList
(and inheritICollection
andIEnumerable
). Arrays implicitly derive fromSystem.Array
, which implementsIList
. So, they're both lists (but you can't use some methods from the aforementioned interfaces with an array - it's still a fixed number of elements). You could serialize this collection and base64-encode it, then make sure it gets sent with your form data to the next page, deserializing it. If you're remaining on the same page (i.e., using post-back), you could also extend thePage
class (your .aspx and code-behind files do this already) and overrideSaveViewState
andLoadViewState
to save this serialized collection, but this only works if using post-back with the same page. You should definitely read the documentation on those two methods - implementing them can be tricky, especially if you don't know what you're doing.Microsoft MVP, Visual C# My Articles
The only way to pass data between forms is using Session, isn't it ? Free your mind...
-
The only way to pass data between forms is using Session, isn't it ? Free your mind...
No, it's not the only way. Any data defined as an input for the page form can be sent to another page, which can retrieve it using
Request.Forms
(POST),Request.QueryString
(GET), orRequest.Params
(both). How do you think CGI has worked since it was proposed? This data doesn't have to be input by the user - it can simply be in a hidden input field. The developer just has to make sure it gets in there before the GET or POST request is sent to another page (since that data is sent from the client to the new page).Microsoft MVP, Visual C# My Articles
-
No, it's not the only way. Any data defined as an input for the page form can be sent to another page, which can retrieve it using
Request.Forms
(POST),Request.QueryString
(GET), orRequest.Params
(both). How do you think CGI has worked since it was proposed? This data doesn't have to be input by the user - it can simply be in a hidden input field. The developer just has to make sure it gets in there before the GET or POST request is sent to another page (since that data is sent from the client to the new page).Microsoft MVP, Visual C# My Articles
I know that this is not the only way to share info between forms. I've done some ASP and CGI. I didn't explain myself with the question... I meant, is that the only way to do it using ASP.NET ? Free your mind...
-
I know that this is not the only way to share info between forms. I've done some ASP and CGI. I didn't explain myself with the question... I meant, is that the only way to do it using ASP.NET ? Free your mind...
Well, besides sessions and and form data (thus meaning that sessions still aren't the only way in ASP.NET), you could always store it in a repository of sorts, like a database, file (bad!), cookie, etc. The nice thing about using a session is that the original poster wouldn't have to serialize the collection and could just store it in the session as-is. Sessions can be very nice, but they are often over-used (especially when large amounts of data are stored in them). As I mentioned before, too, if you use post-back and stay on the same page (seems to be most common with ASP.NET), you can use the ViewState but the page implementation is responsible for saving and loading that ViewState (and one must be careful when doing so).
Microsoft MVP, Visual C# My Articles