Using enums as usercontrol public properties

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
 
C

Cowboy \(Gregory A. Beamer\)

<%%> 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!
*************************************************
 
B

badger

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!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top