How do I validate the values entered for custom control properties?

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default How do I validate the values entered for custom control properties?

    I have a custom control with properties named MinValue, MaxValue, and Value
    (all of which I have assigned a DefaultValue design-time attribute). The
    Value property must be between (or equal to) the MinValue and MaxValue
    properties in order to avoid a runtime error. I want to give an error during
    the usage of the control stating this, as well as prevent it from compiling
    under these conditions. Because this is something I have never done with
    custom controls before, I need some help here. Thanks.
    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. Default Values for Control Properties
      I have a custom control that has a bunch of properties on it. I added the DefaultValue attribute to it and it all seems to work fine with showing...
    2. Making Custom Control Properties Visible in Visual Studio's Properties Palette
      I am learning how to use the System.ComponentModel class in VB.NET so that I can add my ASP.NET controls to Visual Studio .NET 2003. I have managed...
    3. Getting values entered into (dynamicly loaded control)
      I've dynamicly loaded user control (.ascx file) into my page via Page.LoadControl() method. The control has been added to Controls collection of...
    4. How to access values entered in User control in the main page.
      Hi Guys, i have a user control which allows the user to enter Name& Address in text boxes. I use the same user control in the main page... ...
    5. Specifying dynamic default values for properties in custom controls:
      Hey guys, I have a custom int property in my control whose default value is dynamic, so I cannot specify a "DefaultValue" attribute. However, I...
  3. #2

    Default Re: How do I validate the values entered for custom control properties?

    One way would be to throw an exception if the value is out of range - Visual
    Studio will catch this exception and not allow the user to change to invalid
    values.


    ---------
    - G Himangi, Sky Software [url]http://www.ssware.com[/url]
    Shell MegaPack : Drop-In Explorer GUI Controls For Your Apps (.Net & ActiveX
    Editions Available)
    EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
    EZShellExtensions.Net : Develop all shell extensions rapidly in .Net
    ---------



    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:Olw3uQIrGHA.4692@TK2MSFTNGP02.phx.gbl...
    >I have a custom control with properties named MinValue, MaxValue, and Value
    >(all of which I have assigned a DefaultValue design-time attribute). The
    >Value property must be between (or equal to) the MinValue and MaxValue
    >properties in order to avoid a runtime error. I want to give an error
    >during the usage of the control stating this, as well as prevent it from
    >compiling under these conditions. Because this is something I have never
    >done with custom controls before, I need some help here. Thanks.
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >

    G Himangi Guest

  4. #3

    Default Re: How do I validate the values entered for custom control properties?

    That will not work in all situations. For example, if the current values are
    MinValue=75, MaxValue=100, Value=80 and the user wants to change them to
    MinValue=25, MaxValue=50, Value=40. This will force the user to change them
    in a certain order, which could be very annoying. I want the user to be
    notified, but still be allowed to change them, and simply not be allowed to
    compile it if they are out of range. Also, if I did use your exception idea,
    where in my code would I put it? Thanks.
    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]

    "G Himangi" <info@ssware.com> wrote in message
    news:empcjVJrGHA.3256@TK2MSFTNGP04.phx.gbl...
    > One way would be to throw an exception if the value is out of range -
    > Visual Studio will catch this exception and not allow the user to change
    > to invalid values.
    >
    >
    > ---------
    > - G Himangi, Sky Software [url]http://www.ssware.com[/url]
    > Shell MegaPack : Drop-In Explorer GUI Controls For Your Apps (.Net &
    > ActiveX Editions Available)
    > EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
    > EZShellExtensions.Net : Develop all shell extensions rapidly in .Net
    > ---------
    >
    >
    >
    > "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    > news:Olw3uQIrGHA.4692@TK2MSFTNGP02.phx.gbl...
    >>I have a custom control with properties named MinValue, MaxValue, and
    >>Value (all of which I have assigned a DefaultValue design-time attribute).
    >>The Value property must be between (or equal to) the MinValue and MaxValue
    >>properties in order to avoid a runtime error. I want to give an error
    >>during the usage of the control stating this, as well as prevent it from
    >>compiling under these conditions. Because this is something I have never
    >>done with custom controls before, I need some help here. Thanks.
    >> --
    >> Nathan Sokalski
    >> [email]njsokalski@hotmail.com[/email]
    >> [url]http://www.nathansokalski.com/[/url]
    >>
    >
    >

    Nathan Sokalski Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139