Using enums as usercontrol public properties

  • Thread starter Thread starter badger
  • Start date Start date
B

badger

Hi,

I have created a usercontrol with a public property as follows:

// default display type to single form.
private DisplayType selectedDisplayType =
LoginForm.DisplayType.SingleForm;

public enum DisplayType
{
SingleForm = 0,
MultiForm = 1,
}

public DisplayType SelectedDisplayType
{
get {return this.selectedDisplayType;}
set {this.selectedDisplayType = value;}
}

I would like to set the valuse of the user controls public property in
the parent ASPX page as follows:

<myUserControl:Login id="l1" runat="server" SelectedDisplayType='<%#
LoginForm.DisplayType.MultiForm %>' />

BUT it does not seem to set the setter in the public property. If I
change the ASPX code to :

<myUserControl:Login id="l1" runat="server" SelectedDisplayType="1" />

It works fine.

Any thoughts on what I am doing wrong?

TIA
 
<%%> is evaluated after the form paint already begins. If you want to alter
a control in this manner, you will have to repaint it, which is tricky with
web controls.

You are best to set these types of properties in the CodeBehind. You will
have to create a declaration for the control, but then you can set any
public properties on the control ... and if you pick the correct event, this
happens prior to painting the control.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Thanks Cowboy.

<%%> is evaluated after the form paint already begins. If you want to alter
a control in this manner, you will have to repaint it, which is tricky with
web controls.

You are best to set these types of properties in the CodeBehind. You will
have to create a declaration for the control, but then you can set any
public properties on the control ... and if you pick the correct event, this
happens prior to painting the control.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Back
Top