ShareThis

Thursday, June 21, 2012

[ASP] Get enum int value from aspx markup in javascript

This stumbled me as casting to an (int) in the markup like this did not work:

case <%= (int) MyEnumType.USA %>:
case <%= Int32.Parse(MyEnumType.USA) %>:
The correct usage is with Convert.ChangeType(...) method:

<%= Convert.ChangeType(MyEnum.USA, MyEnum.USA.GetTypeCode()) %>

0 comments:

Post a Comment