By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,882 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,882 IT Pros & Developers. It's quick & easy.

c# Custom control properties

P: 6
Hi,

Can any body help me adding properties to my web control. In my control I want a property and with that property I need its default values like value1,value2,value3.

Please let me know how to add such a property and how to add default values to it.


How can I do that. I have more than 10 controls in my web control. Can any one have any idea how to do this ?
Apr 19 '07 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Hi,

Can any body help me adding properties to my web control. In my control I want a property and with that property I need its default values like value1,value2,value3.

Please let me know how to add such a property and how to add default values to it.


How can I do that. I have more than 10 controls in my web control. Can any one have any idea how to do this ?
Hi! Welcome to theScripts!

Just like you have public and private variables in your user controls, you can have public and private Properties.

For example:
Expand|Select|Wrap|Line Numbers
  1.  Partial Class myCustomUserControl
  2.         Inherits System.Web.UI.UserControl
  3.      ...
  4.  
  5.      Private var1
  6.      Private var2
  7.  
  8.      Public Property  Var1sProperty()
  9.           Get
  10.              return var1
  11.           End Get
  12.           Set (ByVal value)
  13.               var1=value
  14.           End Set
  15.        End Property
  16.  
  17. ...
  18.  
  19.         Private Sub.....
  20.  
  21. End Class
  22.  
  23.  
Hope this was helpful! :)

-Frinny
Apr 19 '07 #2

P: 6
Ya that is fine. Let me give me some more details.
I am developing a payment user control which can be used in any application.
I have two variables with their predefined values

And want to give them to be set by the coder who is developing a specific payment system.

So on my ascx page I have card type , card number , security code and expiration date.

along with that i need two properties which can be settled according to the application.

What should i do ?


Hi! Welcome to theScripts!

Just like you have public and private variables in your user controls, you can have public and private Properties.

For example:
Expand|Select|Wrap|Line Numbers
  1.  Partial Class myCustomUserControl
  2.         Inherits System.Web.UI.UserControl
  3.      ...
  4.  
  5.      Private var1
  6.      Private var2
  7.  
  8.      Public Property  Var1sProperty()
  9.           Get
  10.              return var1
  11.           End Get
  12.           Set (ByVal value)
  13.               var1=value
  14.           End Set
  15.        End Property
  16.  
  17. ...
  18.  
  19.         Private Sub.....
  20.  
  21. End Class
  22.  
  23.  



Hope this was helpful! :)

-Frinny
Apr 20 '07 #3

Frinavale
Expert Mod 5K+
P: 9,731
Ya that is fine. Let me give me some more details.
I am developing a payment user control which can be used in any application.
I have two variables with their predefined values

And want to give them to be set by the coder who is developing a specific payment system.

So on my ascx page I have card type , card number , security code and expiration date.

along with that i need two properties which can be settled according to the application.

What should i do ?
Make your card number , security code and expiration date variables private so that they are not accessible from the outside.

Define the to properties that can be settled according to the application using Public properties.

Public properties allow other applications to access variables inside your control.

The other programmer would create an instance of your control and then would have access to the public properties.
Apr 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.