How To access base class property from user control?

O

oliviers

Here is my scenario:
I first create a base class with one property :
public class MyControl
inherits System.Web.UI.UserControl
Public readonly property IsEditable() boolean
Get
Return False '(More code later)
End Get
End property
End Class

I then create my different usercontrols, deriving from MyControl:
Public class aControl
inherits MyControl
...
End Class

My goal is to make the IsEditable property available when designing my
controls.
So if I use a <asp:hyperlink> control in the aControl control, I'd
like to use the following design source code:
<asp:HyperLink ID="myLink" runat="server" ImageUrl="myImage.gif"
visible='<%# IsEditable %>'></asp:HyperLink>

I guess it should work as I don't get compilation errors but no code
is executing. The link remains visible, I never reach the breakpoint I
set in the property Get code to check what's happening.

Am I missing something?

Olivier
 
T

Teemu Keiski

You are using databinding syntax to set the the Visible property, do you
call control.DataBind somewhere to databind the control?
 
G

Guest

You're using binding expression but not calling ddataBind method anywhere.
myLink.DataBind()
Data binding expressions <%# %> are usually used within data bound controls
like gridview, formview, detailsview, etc.. If you want to use them ouside
any non-template/data bound control, you must call DataBind() explicitly in
code behind/beside. Usually it's enough to call databind() of the executing
page, but it's not effective and intriduces issuies to all already bound
controls. Therefore, in this case it's better to assign values in code behind:

myLink.Visible = IsEditable
 
O

oliviers

You're using binding expression but not calling ddataBind method anywhere.
myLink.DataBind()
Data binding expressions <%# %> are usually used within data bound controls
like gridview, formview, detailsview, etc.. If you want to use them ouside
any non-template/data bound control, you must call DataBind() explicitly in
code behind/beside. Usually it's enough to call databind() of the executing
page, but it's not effective and intriduces issuies to all already bound
controls. Therefore, in this case it's better to assign values in code behind:

myLink.Visible = IsEditable

--
Milosz










- Afficher le texte des messages précédents -

Oops, thanks for those comments.

Olivier
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top