473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How To access base class property from user control?

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:hyperlinkcontrol 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

Feb 15 '07 #1
3 5471
You are using databinding syntax to set the the Visible property, do you
call control.DataBind somewhere to databind the control?
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"oliviers" <ol************@gmail.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
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:hyperlinkcontrol 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
Feb 15 '07 #2
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
"oliviers" wrote:
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:hyperlinkcontrol 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

Feb 15 '07 #3
On 15 fév, 16:53, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
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

"oliviers" wrote:
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:hyperlinkcontrol 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- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Oops, thanks for those comments.

Olivier

Feb 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
3
by: Mikip | last post by:
Hi, I have some properties that are common to all pages so I have created a base class which every page inherits from. I now also want to use these properties within User Controls on the page....
10
by: Davíđ Ţórisson | last post by:
Please can someone tell me how on earth to create an instance of my top level (base) Page class so that I can access it's objects from an user control?? Someone told me public myParent =...
3
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
5
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.