DefaultValue for Public Property of ASP.NET 2.0 UserControl not appearing in Properties Window

Discussion in 'ASP .Net Building Controls' started by Shadow Lynx, Feb 28, 2006.

  1. Shadow Lynx

    Shadow Lynx Guest

    First, I'm using Visual Web Developer 2005 Express Edition, which I
    hope is exactly the same as Visual Studio 2005 minus a bunch of useful
    features.
    While the property itself (Amount) appears as it should in the
    Properties Window, the DefaultValue is never set (it is always blank).
    If I enter the default value, it is not bold, indicating that it is at
    least aware of what the DefaultValue should be. The strangest thing is
    that, in Source view, the DefaultValue DOES appear in the Properties
    Window! What's the deal!? Here's a very simple example:

    ASCX:
    <%@ Control Language="VB" AutoEventWireup="false"
    CodeFile="TestControl.ascx.vb" Inherits="TestControl" %>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    ASCX.VB:
    Imports System.ComponentModel
    Partial Class TestControl
    Inherits System.Web.UI.UserControl
    Private _Amount As Integer = 100
    <DefaultValue(100)> _
    Public Property Amount() As Integer
    Get
    Return _Amount
    End Get
    Set(ByVal value As Integer)
    _Amount = value
    End Set
    End Property
    End Class

    ASPX:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb"
    Inherits="Test" %>
    <%@ Register Src="TestControl.ascx" TagName="TestControl"
    TagPrefix="uc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Test</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <uc1:TestControl ID="TestControl1" runat="server" />
    </div>
    </form>
    </body>
    </html>

    ASPX.VB:
    Partial Class Test
    Inherits System.Web.UI.Page
    End Class

    I'd also like to know if there's any way to add resizing handles (along
    with the associated Width and Height properties) to a UserControl.
    That's the ultimate goal of this exercise - to make a UserControl that
    is sizable via handles in the designer as well as linked Width and
    Height properties. I tried using a panel to surround all of the
    controls in my UserControl and linking Width and Height to its Width
    and Height, but to no avail (at least in the designer there was no
    change.)

    <ASP:RANT>
    Last question which is completely unimportant: Does it drive anyone
    else nuts when you're editng the Attributes <...> of a
    Property/Class/etc. and it horizontally shifts the first line of the
    definition line into a screwy, non-tabbed position? This happened to
    me in VS 2003 as well as this VWD 2005.

    <Description("Whatever")> _
    Public Property Thingy() As Integer
    ' The line above shifts left 3 characters
    ' when changing any Attribute. Annoying!
    ...
    End Property
    </ASP:RANT>
    Shadow Lynx, Feb 28, 2006
    #1
    1. Advertising

  2. Shadow Lynx

    DWS Guest

    RE: DefaultValue for Public Property of ASP.NET 2.0 UserControl not ap

    Shadow,
    First thanks for downloading the express edition. Hopefully you've got all
    of em. I lucked out and got a standard edition by attending a launch event.
    Don't forget to grab your free graphics, I'm already using a bunch on my dev
    web site.

    For your qeustion Its by design defaults are not included in the page
    markup. Don't worry ASP.Net will compile the default value into the dll for
    the page. If you change your default do you want to contact every user that
    downloaded your control they have to change their pages? No you send them
    the updated dll. What if the default is localized?

    Good Luck
    DWS

    "Shadow Lynx" wrote:

    > First, I'm using Visual Web Developer 2005 Express Edition, which I
    > hope is exactly the same as Visual Studio 2005 minus a bunch of useful
    > features.
    > While the property itself (Amount) appears as it should in the
    > Properties Window, the DefaultValue is never set (it is always blank).
    > If I enter the default value, it is not bold, indicating that it is at
    > least aware of what the DefaultValue should be. The strangest thing is
    > that, in Source view, the DefaultValue DOES appear in the Properties
    > Window! What's the deal!? Here's a very simple example:
    >
    > ASCX:
    > <%@ Control Language="VB" AutoEventWireup="false"
    > CodeFile="TestControl.ascx.vb" Inherits="TestControl" %>
    > <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    >
    > ASCX.VB:
    > Imports System.ComponentModel
    > Partial Class TestControl
    > Inherits System.Web.UI.UserControl
    > Private _Amount As Integer = 100
    > <DefaultValue(100)> _
    > Public Property Amount() As Integer
    > Get
    > Return _Amount
    > End Get
    > Set(ByVal value As Integer)
    > _Amount = value
    > End Set
    > End Property
    > End Class
    >
    > ASPX:
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb"
    > Inherits="Test" %>
    > <%@ Register Src="TestControl.ascx" TagName="TestControl"
    > TagPrefix="uc1" %>
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Test</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <uc1:TestControl ID="TestControl1" runat="server" />
    > </div>
    > </form>
    > </body>
    > </html>
    >
    > ASPX.VB:
    > Partial Class Test
    > Inherits System.Web.UI.Page
    > End Class
    >
    > I'd also like to know if there's any way to add resizing handles (along
    > with the associated Width and Height properties) to a UserControl.
    > That's the ultimate goal of this exercise - to make a UserControl that
    > is sizable via handles in the designer as well as linked Width and
    > Height properties. I tried using a panel to surround all of the
    > controls in my UserControl and linking Width and Height to its Width
    > and Height, but to no avail (at least in the designer there was no
    > change.)
    >
    > <ASP:RANT>
    > Last question which is completely unimportant: Does it drive anyone
    > else nuts when you're editng the Attributes <...> of a
    > Property/Class/etc. and it horizontally shifts the first line of the
    > definition line into a screwy, non-tabbed position? This happened to
    > me in VS 2003 as well as this VWD 2005.
    >
    > <Description("Whatever")> _
    > Public Property Thingy() As Integer
    > ' The line above shifts left 3 characters
    > ' when changing any Attribute. Annoying!
    > ...
    > End Property
    > </ASP:RANT>
    >
    >
    DWS, Feb 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,340
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    544
    SpamProof
    Oct 21, 2003
  3. Kevin Spencer
    Replies:
    2
    Views:
    3,305
    Kevin Spencer
    Sep 15, 2004
  4. Syd_Man
    Replies:
    0
    Views:
    341
    Syd_Man
    Dec 5, 2006
  5. KJ
    Replies:
    0
    Views:
    122
Loading...

Share This Page