Custom Controls with non-String Attributes

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jun 24, 2006.

  1. I want to add attributes to my custom controls that are not of type String.
    I know how to convert from a String to the different types that I want, but
    when the user assigns values to the attributes using properties (assigns the
    values programmatically) I want them to be able to use the type I would be
    converting the attribute to. For example, here are the two basic scenarios:

    Assigning the value using attributes:

    <mytags:linkmaker runat="server" id="linkmaker1"
    url="http://www.nathansokalski.com/"></mytags:linkmaker>

    Assigning the value programmatically:

    linkmaker1.url=New Uri("http://www.nathansokalski.com/")

    The problem is that if I make the property of type Uri I recieve a Parser
    Error, and if I make it a String the user cannot programmatically assign a
    Uri to it. What do I do? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jun 24, 2006
    #1
    1. Advertising

  2. Don't expose the url property. Instead, expose an intermediate property
    that returns type URI. When the property is set, set the url property of
    the linkmaker object, when it's requested, convert the value of the
    linkmaker url to a URI and return it.

    HTH

    "Nathan Sokalski" <> wrote in message
    news:...
    >I want to add attributes to my custom controls that are not of type String.
    >I know how to convert from a String to the different types that I want, but
    >when the user assigns values to the attributes using properties (assigns
    >the values programmatically) I want them to be able to use the type I would
    >be converting the attribute to. For example, here are the two basic
    >scenarios:
    >
    > Assigning the value using attributes:
    >
    > <mytags:linkmaker runat="server" id="linkmaker1"
    > url="http://www.nathansokalski.com/"></mytags:linkmaker>
    >
    > Assigning the value programmatically:
    >
    > linkmaker1.url=New Uri("http://www.nathansokalski.com/")
    >
    > The problem is that if I make the property of type Uri I recieve a Parser
    > Error, and if I make it a String the user cannot programmatically assign a
    > Uri to it. What do I do? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Tim Dot NoSpam, Jun 26, 2006
    #2
    1. Advertising

  3. I'm not sure what you mean by that. Is there a small code snippet or example
    I could see? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Tim Dot NoSpam" <> wrote in message
    news:...
    > Don't expose the url property. Instead, expose an intermediate property
    > that returns type URI. When the property is set, set the url property of
    > the linkmaker object, when it's requested, convert the value of the
    > linkmaker url to a URI and return it.
    >
    > HTH
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >>I want to add attributes to my custom controls that are not of type
    >>String. I know how to convert from a String to the different types that I
    >>want, but when the user assigns values to the attributes using properties
    >>(assigns the values programmatically) I want them to be able to use the
    >>type I would be converting the attribute to. For example, here are the two
    >>basic scenarios:
    >>
    >> Assigning the value using attributes:
    >>
    >> <mytags:linkmaker runat="server" id="linkmaker1"
    >> url="http://www.nathansokalski.com/"></mytags:linkmaker>
    >>
    >> Assigning the value programmatically:
    >>
    >> linkmaker1.url=New Uri("http://www.nathansokalski.com/")
    >>
    >> The problem is that if I make the property of type Uri I recieve a Parser
    >> Error, and if I make it a String the user cannot programmatically assign
    >> a Uri to it. What do I do? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
    >
     
    Nathan Sokalski, Jun 26, 2006
    #3
  4. Hello, I'm creating a custom web control and i need to set some properties
    for it.
    I would like to have some properties with integer values validation, colors
    palette and a drop down list with some established options.
    So far i've declared some reference values like integer and its
    setIntegerValue functions. Also i declared a System.Draw.Color color_var_name
    variable and defined a "set color" function to receive the values in the
    properties menu after clicking the web control.
    The "setColor" properties displays a dropdown list with values as cyan,
    black and so on. I would like to know if its possible to use a palette with
    color picker instead and also to declare some validation for the entered
    integer values or a predefinded range.
    Another question is if there is a method to have embebbed javascript and css
    files with the web control. I know there is one with the server control.
    I'm quite new to .net and I would appreciate any help.
    Thanks a lot in advance.
     
    Marco Antonio, Jun 28, 2006
    #4
    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. Nathan Sokalski

    Custom Controls with non-String Attributes

    Nathan Sokalski, Jun 24, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    413
    =?Utf-8?B?TWFyY28gQW50b25pbw==?=
    Jun 28, 2006
  2. P4trykx
    Replies:
    2
    Views:
    1,845
    bruce barker
    Jan 31, 2007
  3. rodchar
    Replies:
    0
    Views:
    399
    rodchar
    Nov 26, 2007
  4. Nathan Sokalski

    Custom Controls with non-String Attributes

    Nathan Sokalski, Jun 24, 2006, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    122
    Marco Antonio
    Jun 28, 2006
  5. Gerald Bauer
    Replies:
    1
    Views:
    128
    Gerald Bauer
    Jul 21, 2008
Loading...

Share This Page