|
-
May 28th, 2010, 12:26 PM
#1
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 
-
May 29th, 2010, 02:01 AM
#2
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
-
May 29th, 2010, 02:20 AM
#3
Frenzied Member
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 
-
May 29th, 2010, 03:29 AM
#4
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 
-
May 29th, 2010, 04:13 AM
#5
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.
-
May 29th, 2010, 04:15 AM
#6
Frenzied Member
Re: User Control - Must supply property
 Originally Posted by motil
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 
-
May 29th, 2010, 04:19 AM
#7
Frenzied Member
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 
-
May 29th, 2010, 04:21 AM
#8
Frenzied Member
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 
-
May 29th, 2010, 04:36 AM
#9
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 
-
May 29th, 2010, 04:49 AM
#10
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...
-
May 29th, 2010, 04:49 AM
#11
Frenzied Member
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 
-
May 29th, 2010, 04:57 AM
#12
Frenzied Member
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 
-
May 29th, 2010, 05:09 AM
#13
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
-
May 29th, 2010, 05:19 AM
#14
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 
-
May 29th, 2010, 06:16 AM
#15
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
-
May 29th, 2010, 06:21 AM
#16
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 
-
May 29th, 2010, 06:34 AM
#17
Re: User Control - Must supply property
Are you designing a User Control or a Server Control?
-
May 29th, 2010, 06:43 AM
#18
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|