Results 1 to 18 of 18

Thread: User Control - Must supply property

  1. #1

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    User Control - Must supply property

    Hi guys, i built a user control and i want to make one of its properties as a must, that's mean if you not supply this control when you create the control the project won't be compile, just like if you omit the runat="server" property.

    any suggestions ?

    Best Regards,

    Motil.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: User Control - Must supply property

    I think you would need to create your own user control class and specify the required parameters in the constructor, that way when it's instantated you have to pass the parameters , if not that should cause a build error.... That's my guess.

    http://msdn.microsoft.com/en-us/libr...ercontrol.aspx

  3. #3
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    hey,
    i think you can pass your property in your class contractor
    and if it was null then throw your error.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  4. #4

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: User Control - Must supply property

    couldn't pull it off so far, my best shot so far was to create an interface with the required property and implement it from my user control class but that didn't did the trick also. this is really strange that there is so little information about this over the internet.

    anyways i can live without it for now, if i'll ever pull it off I'll make sure to post it here.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  5. #5
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: User Control - Must supply property

    Your right a default constructor is required or you cant inherit your user control from that class

    I've had the same problem before but obviously didn't solve it, I'm going to do some more thinking on it.

  6. #6
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    Quote Originally Posted by motil View Post
    couldn't pull it off so far, my best shot so far was to create an interface with the required property and implement it from my user control class but that didn't did the trick also. this is really strange that there is so little information about this over the internet.

    anyways i can live without it for now, if i'll ever pull it off I'll make sure to post it here.
    hey motil,
    can you send us your interface ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  7. #7
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    what about creating a property
    Code:
    using System;
    
    
    /// <summary>
    /// this class for test 
    /// </summary>
    public class TestClass
    {
        #region private member(s)
        private string _id = null;
        #endregion
    
        #region public property(s)
        public string ID
        {
            set
            {
                _id = value;
            }
        }
        #endregion
    
        public TestClass()
    	{
            string getMyId = ID;
            if (getMyId == null)
                throw new Exception();
    	}
    }
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  8. #8
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    what about creating a property such as
    Code:
    using System;
    
    
    /// <summary>
    /// this class for test 
    /// </summary>
    public class TestClass
    {
        #region private member(s)
        private string _id = null;
        #endregion
    
        #region public property(s)
        public string ID
        {
            set
            {
                _id = value;
            }
        }
        #endregion
    
        public TestClass()
    	{
            string getMyId = ID;
            if (getMyId == null)
                throw new Exception();
    	}
    }
    i don't know may be this can do it, or what you think ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  9. #9

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: User Control - Must supply property

    avrail - it's very simple interface for testing purpose :
    Code:
     interface Testing
        {
             int Test { get; set; }
        }
    and thanks for the code but what you have there will work (with some modifications) only @ runtime while i want the error will raise @ design time (project will not be able to compile).

    thanks again.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  10. #10
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: User Control - Must supply property

    In your interface make your property "Must Have" and I think it will have to implement IControl maybe that will work.... It's alot of trouble to get a required property on a userControl...

  11. #11
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    hey motil,
    thanks for what, if i was in your position you will help, don't you
    please after your modification let me see.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  12. #12
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: User Control - Must supply property

    by the way, the class need get {}
    sorry.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: User Control - Must supply property

    Hmmm, I was sure that there would be a way to do this easily, it seems like there is a property attribute for everything else:

    http://www.bipinjoshi.net/articles/4...184de5217.aspx

    But not whether to indicate that a property is required, which I find a little strange, I am going to have to do some digging.

    Gary

  14. #14

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: User Control - Must supply property

    @brin351 how do i set the property as "must have" ?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  15. #15
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: User Control - Must supply property

    Sorry I was on the wrong track I tried creating an interface and implementing it in the usercontrol along with the property in the interface but this did not force a design time need for that property, You already knew that...

    I tried again with a base class with no default constructor but could not get it --- I think runtime is the only way throw an error unless you reinvent the wheel

  16. #16

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: User Control - Must supply property

    ok brin351 thanks for your efforts!
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  17. #17
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: User Control - Must supply property

    Are you designing a User Control or a Server Control?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  18. #18

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: User Control - Must supply property

    User Control ( I'm not sure I know what is server control)
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

Posting Permissions

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



Click Here to Expand Forum to Full Width