Back to Devexpress

Preserving Value Types

aspnet-5763-components-multi-use-site-controls-hiddenfield-concepts-preserving-value-types.md

latest1.3 KB
Original Source

Preserving Value Types

  • Jun 21, 2024

The types of values maintained by the ASPxHiddenField component are automatically preserved, regardless of whether you write server code (using C# or VB) or client code (using JavaScript).

The following code demonstrates how to insert a DateTime value on the server side into the control’s value collection:

csharp
ASPxHiddenField1["myBirthDay"] = new DateTime(1985, 8, 29);

On the client side, you can access and modify this value as a Date object:

javascript
var date = ASPxHiddenField1.Get("myBirthDay");
date.setHours(15, 23); // You can manipulate the obtained value as a date value.
ASPxHiddenField1.Set("myBirthDay", date);

On the server side, you can again manipulate this value as a DateTime object:

csharp
DateTime date = (DateTime)ASPxHiddenField1["myBirthDay"];
int hour = date.Hour; // This value is 15.

See Also

Supported Data Types