Aximili
Aximili

Reputation: 29484

Custom attribute in UserControl (*.ascx)?

Supposing I have a user control like this

<MyTag:MyWidget runat="server" />

I am wondering if I can do something like

<MyTag:MyWidget runat="server" MemberHeight="400" PublicHeight="200" />

So that in MyWidget.ascx I can have

<div height="<%=IsLoggedIn ? MemberHeight : PublicHeight%>">

or something like that...? Because I want the height to vary in each page that is using this widget.

Upvotes: 28

Views: 28434

Answers (2)

longhairedsi
longhairedsi

Reputation: 3136

You need to define public properties for both items, as such:

public int MemberHeight{ get; set; }
public int PublicHeight{ get; set; }

Upvotes: 16

Steve Wellens
Steve Wellens

Reputation: 20638

Add a public property to the UserControl class something like...

 public int MySize { get; set; }

Upvotes: 36

Related Questions