开发者

Custom attribute in UserControl (*.ascx)?

开发者 https://www.devze.com 2023-02-15 11:27 出处:网络
Supposing I have a user control like this <MyTag:MyWidget runat=\"server\" /> I am wondering if I can do something like

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 ? Membe开发者_JAVA技巧rHeight : PublicHeight%>">

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


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

 public int MySize { get; set; }


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

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

精彩评论

暂无评论...
验证码 换一张
取 消