How To access base class property from user control?

  • Thread starter Thread starter oliviers
  • Start date Start date
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
 
You are using databinding syntax to set the the Visible property, do you
call control.DataBind somewhere to databind the control?
 
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
 
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
 
Back
Top