Ticket T459246
Visible to All Users

ASPxHiddenField - It is impossible to get the Generic List<T> from the hidden field

created 8 years ago

According to this: https://documentation.devexpress.com/#AspNet/CustomDocument5762 the ASPxHiddenField supports all lists that implements the IList interface.

I created the following class in order to use a List<logItem> of them and pass it to the ASPxHiddenField, but when I try to use it the application throws an error. I had to implement a string representation of the objects and created a list of type: List<string>, using this approach I'm able to send and receive the List<string> using the ASPxHiddenField.

¿Is this the only way or can I use directly the List<logItem> object with the ASPxHiddenField?

C#
public class logItem { public int errorCode { get; set; } public string key { get; set; } public string Description { get; set; } public DateTime timeStamp { get; set; } public logItem(int _errorCode, string _key, string _Description) { this.errorCode = _errorCode; this.key = _key; this.Description = _Description; this.timeStamp = DateTime.Now; } public logItem(string rep) { var arr = rep.Split('|'); errorCode = int.Parse(arr[0]); key = arr[1]; Description = arr[2]; timeStamp = DateTime.Parse(arr[3]); } public override string ToString() { return string.Format("{0}|{1}|{2}|{3}", errorCode, key, Description, timeStamp); } } //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ //Trying to use the ASPxHiddenField System.Collections.Generic.List<string> errorsList = new System.Collections.Generic.List<string>(); //Changed to string representation errorsList.Add(new UserControls.logItem(1, "mat1", "material 1").ToString()); errorsList.Add(new UserControls.logItem(2, "mat2", "material 2").ToString()); errorsList.Add(new UserControls.logItem(3, "mat3", "material 3").ToString()); ASPxHiddenFieldErrors.Set("ErrorsList", errorsList); //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ //Reading the ASPxHiddenField var param = (List<string>)hiddenFieldErrorList.Get("ErrorsList");
Comments (1)
DevExpress Support Team 8 years ago

    Hello Guillermo,

    Thank you for your code. I reproduced the same behavior on my side and passed this information to our developers to analyze. We will research it and answer you once we get any result. In the meantime, you can use a workaround with the string conversion.

    I see you are using version 12.2.18. Please also note that if we find a way to solve the problem, the update to the newest version of our controls will be required.

    Answers approved by DevExpress Support

    created 8 years ago

    Hello Guillermo,

    We have ended our research. The main idea in the documentation is that the generic list can be correctly passed to the hidden field if the list atomic element types from the Elements list in the help article. So, your solution is correct: to correctly pass the list with the logItem type, you can convert it to the string and use the list of the string type to fill the hidden field.

    I also created a separate ticket on your behalf: Documentation - ASPxHiddenField - Update the Data Types Supported by the ASPxHiddenField help article to update our documentation. To overcome confusion in future.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.