CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 3/30/2005 2:41:34 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 11 Views: 9 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
12 Items, 1 Pages 1 |< << Go >> >|
rmelancon
Asp.Net User
Overriding width property on a custom server control3/30/2005 2:41:34 PM

0/0

I have a custom web server control that consists of three dropdowns.  I am trying to override the Width property and set it to a default width of 128 pixels.  The property is defined as follows:

<Bindable(True), Category("Appearance"), DefaultValue("128px")> Overrides Property [Width]() As Unit
        Get
            EnsureChildControls()
            Return mWidth
        End Get

        Set(ByVal Value As Unit)
            EnsureChildControls()
            mWidth = Value
        End Set
End Property

In the New method I set mWidth to Unit.Pixels(128).  Originally I tried DefaultValue(Unit.Pixels(128)) in the attribute of the property because that made more sense than putting the string "128px" but the compiler complained.  I'm obviously doing something wrong, any ideas?

Thanks, Robb

bmains
Asp.Net User
Re: Overriding width property on a custom server control3/30/2005 5:27:47 PM

0/0

Does DefaultValue("128px") work?
Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
joteke
Asp.Net User
Re: Overriding width property on a custom server control3/30/2005 6:43:39 PM

0/0

Try setting the attribute this way

DefaultValue(GetType(Unit), "128px")

By the way does mWidth itself depend on child controls or do child controls use that value? I'm just wondering as mWidth is not directly accessing any subcontrol's property, that does it need the child control creation (as child controls are created before returning or setting the value). Anyways, that wasn't what you asked but I just noticed.


Thanks,

Teemu Keiski
Finland, EU
rmelancon
Asp.Net User
Re: Overriding width property on a custom server control3/31/2005 4:59:49 PM

0/0

No, and neither does DefaultValue(GetType(Unit), "128px").  Must be missing something.
rmelancon
Asp.Net User
Re: Overriding width property on a custom server control3/31/2005 5:21:55 PM

0/0

Well the compiler doesn't complain now with DefaultValue(GetType(Unit), "128px") but it's still not setting the initial width of the control.  Maybe I'm missing something here.  Oh, and to answer your question on mWidth it is just the protected local value behind the public property for width.  Not really sure if I need the EnsureChildControls or not because I'm not really setting the width of the individual elements (the three selects) I'm just trying to set the width of the "rendered" web control.  And what is odd is that if you switch from design to html and back it shows up.  BTW the width is 132 for some odd reason.

Raterus
Asp.Net User
Re: Overriding width property on a custom server control3/31/2005 6:26:48 PM

0/0

The DefaultValue() attribute is only used by the designer, which my guess is you are not using.

Another Question Like Yours
Ask and it will be given to you; seek and you will find; knock and the door will be opened to you. Luke 11:9
joteke
Asp.Net User
Re: Overriding width property on a custom server control3/31/2005 6:35:50 PM

0/0

And you said that you set it yourself in constructor?

 


Thanks,

Teemu Keiski
Finland, EU
rmelancon
Asp.Net User
Re: Overriding width property on a custom server control3/31/2005 7:38:19 PM

0/0

Here's the constructor:

Public Sub New()

mHour = 12

mMinutes = ValidMinutes.Zero

mAMPM = ValidAMPM.AM

mWidth = Unit.Pixel(132)

End Sub

And here's the designer:

Namespace Design
    Public Class TPLDesigner
        Inherits System.Web.UI.Design.ControlDesigner

        Public Overrides Function GetDesignTimeHtml() As String
            Dim sw As New StringWriter
            Dim tw As New HtmlTextWriter(sw)
            Dim cControl As TimePickList = CType(Component, TimePickList)
            cControl.EnsureChildControls()
            cControl.RenderControl(tw)
            Return sw.ToString()
        End Function
    End Class
End Namespace

And here's the attributes line of the control class:

<Designer("Design.TPLDesigner", "Design"), Description("Control to select time of day in 15 minute increments"), DefaultProperty("TimeString"), ToolboxData("<{0}:TimePickList runat=server></{0}:TimePickList>")> _
Public Class TimePickList

imagemaker
Asp.Net User
Re: Overriding width property on a custom server control4/1/2005 1:59:28 AM

0/0

I guess that I'm a little confused as to how you're using mWidth in either CreateChildControls or during rendering of the control and also what it is you mean when you say that the value you set (128px) in the constructor does not "show up" - do you mean in the property grid in design mode or in being able to set the total width of the custom control? Are you overriding the Width property because you don't want the user to be able to change it? If so, I'd go this route:

Have you tried this route (I'm assuming your deriving your custom control from WebControl or one of its derivatives so that it has a Width property):

In constructor:
   MyBase.Width=Unit.Pixel(128)
In property:
   <Browsable (False)> _
   Public Overrides Property Width() As Unit
      Get
         Return Me.Width
      End Get
     Set
         'disable setter so that it width cannot be changed
     End Set
   End Property

Bill, WESNet Designs
rmelancon
Asp.Net User
Re: Overriding width property on a custom server control4/1/2005 12:47:18 PM

0/0

I'm trying to limit the width to 128px.  So I want them to be able to go below 128 but not above.  Which brings up the question of how do you do comparisons on Unit types?  Obviously the code:

if Mybase.width > "128px" then

doesn't work.

Now that I've thought about this more, it doesn't make sense to use a local var mWidth, I should just reference myBase.Width like you show.  So now that I've changed the constructor to MyBase.Width=Unit.Pixel(128), dragging it into the form shows a 128px wide, blank box.  Again if I switch to html view then back to design my "inner" controls show up.  So a 128px blank box is better than what I was getting before but not sure why the inner controls aren't showing up initially.  Also if I just increase the width a little by dragging in the designer, the inner controls appear.

Thanks for all the help,

Robb

imagemaker
Asp.Net User
Re: Overriding width property on a custom server control4/1/2005 2:00:49 PM

0/0

To compare unit types (for pixels only), use the Unit.Value property which returns a double giving the value in pixels.  With this in mind and desiring a lower limit of 128 px wide, you might change the Width property to:

Public Property Width As Unit
   Get
      Return Me.Width
   End Get
   Set (ByVal Value As Unit)
      If Value.Value<128.0 Then Value=Unit.Pixels(128)
      MyBase.Width=Value
   End Set
End Property

As far as the inner controls not showing up initially in the designer, I've seen this happen before when I have not forced the control to recreate its children and rerender after any change has been made.  The following techniques have helped prevent this:

1. Override the Controls property of your custom control to force an EnsureChildControls each time the Control property is referenced:

Public Overrides ReadOnly Property Controls() As ControlCollection
   Get
      EnsureChildControls()
      Return MyBase.Controls
   End Get
End Property

2. In the setter of any property that would change the number of, types of, order of, etc. child controls, set the value of ChildControlsCreated to FALSE.

3. In your custom designer's GetDesignTimeHTML method, reference the custom controls child collection.  Since you have included EnsureChildControls in the overriden Controls property, this should force a recreation of child controls and a re-rendering. Here's an example from one of my control's designers:

Public Class FieldDesigner
   
Inherits System.Web.UI.Design.ControlDesigner
   Public Overrides Function GetDesignTimeHtml() As String
      
Dim DesignTimeHtml As String
      
Dim ControlToDesign As BaseField = CType(Component, BaseField)
      
Dim Controls As ControlCollection = ControlToDesign.Controls 'Reference Controls to force rerendering
      
DesignTimeHtml = MyBase.GetDesignTimeHtml()
      
If DesignTimeHtml.Length = 0 Then DesignTimeHtml = GetEmptyDesignTimeHtml()
      
Return DesignTimeHtml
   
End Function
End Class

Bill, WESNet Designs
rmelancon
Asp.Net User
Re: Overriding width property on a custom server control4/1/2005 2:55:32 PM

0/0

Again thanks for the help.

The width is now working as expected, however the controls still don't get drawn until I "touch" the control ie - start to grow or shrink it, or switch back and forth to design/html.

I basically implemented your designer.  Now do I need to override the GetEmptyDesignTimeHtml also?

12 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 2.0 Server Control and Component Development Authors: Shahram Khosravi, Pages: 1186, Published: 2006
Beginning Visual Web Programming in VB .NET: From Novice to Professional Authors: Daniel Cazzulino, Craig Bowes, Victor Garcia Aprea, Mike Clark, James Greenwood, Chris Hart, Pages: 648, Published: 2005
Hitchhiker's Guide to SQL Server 2000 Reporting Services Authors: Peter Blackburn, William R. Vaughn, Pages: 784, Published: 2004
Pro ASP. Net 3. 5 Server Controls and AJAX Components Authors: Rob Cameron, Dale Michalk, Pages: 740, Published: 2008
Beginning ASP.NET 2.0 Databases: Beta Preview Authors: John Kauffman, Thiru Thangarathinam, Pages: 427, Published: 2005
Mastering ASP.NET with C# Authors: A. Russell Jones, Pages: 816, Published: 2002
ASP.NET 2.0 Cookbook Authors: Michael A. Kittel, Geoffrey T. LeBlond, Pages: 989, Published: 2005
ASP.NET 2.0: Your Visual Blueprint for Developing Web Applications Authors: Chris Love, Pages: 339, Published: 2007
Developing Microsoft ASP.NET Server Controls and Components Authors: Nikhil Kothari, Vandana Datye, Pages: 689, Published: 2002
Developing .NET Custom Controls and Designers Using Visual Basic .NET Authors: James Henry, Pages: 600, Published: 2005

Web:
C#: Google Map Server Control - Part 2 - Custom EPiServer Property Jun 9, 2008 ... re: C#: Google Map Server Control - Part 2 - Custom EPiServer Property. Posted by amila. on 7/13/2008 12:22 PM ...
CodeProject: The XList Server Control. Free source code and ... Width End Get Set(ByVal Value As Unit) MyBase.Width = Value End Set End Property 'Width. Putting the
around the control means overriding ...
Templated Server Control Example The code in the overridden TemplateGroups property defines one template group .... and using it in a page, see Building the Custom Server Control Examples. ...
adding custom properties to a custom server control - ASP.NET Forums I want to add a public property to a custom server control. the property is .... #endregion protected override void Render(HtmlTextWriter output) { output. ...
Creating an Excel Scrolling GridView Custom Control « Ramblings of ... Sep 21, 2007 ... The width property is overridden to allow the scrollbar to be seen if the width ... Tags: gridview, asp.net+3.5, custom+control, c#, Excel ...
CodeProject: XP Style Navigation Bar Server Control with ... In this article, we dealt with creating custom server control with collection property and embedded resources. Collection property holds a collection of ...
Re: WebControl with Collection Property in Design Time From you description, you're developing a custom web server control (in > | asp. net 2.0) which contains a collection .... public override Unit Width ...
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes Aug 8, 2007 ... Utilizing a ListBox, TextBox, ComboBox, TreeView, or custom class as a property in a .NET Windows Forms PropertyGrid control can seem like a ...
IAttributeAccessor Interface If you author a custom server control that inherits from the WebControl, HtmlControl ... Control Implements IAttributeAccessor ' Declare the Width property. ...
Reusable Progress Bar Server Control / Custom Controls / ASP. NET ... Progress bar server control properties. The following properties have been identified as necessary for basic progress bar rendering: Type , Height , Width ...




Search This Site:










vs 2005 create/open website vs is busy

ssl and pop up calendar

currency rate software

sql server 2000

activex ~ an alternative needed

context.items and server.transfer problems

help me! contro disabled

regular expression validator.{0,150}

home page and content skin

loop in global.asax

read regional and language options of client

server.redirect using asp

gridview columnfield?

copying a solution

creating cookies

downloading file in background without save as

profile help!

trigger happy?

portalstore 6.5

addhandler

master page and content refresh

dnn 3.0.5 random bug - file manager, unable to browse to nested folder

multiple querystring values with the same name

security issues with installing printers on intranet

need help with error please

performing multiplication calculation on form

how to load and display pdf folders in a tree view

custom profile provider

visual studio 2005 missing items in toolbox

c# generating an excel file with sql server

 
All Times Are GMT