adding custom properties to a textbox

Discussion in 'ASP .Net' started by Sanjay Pais, Aug 3, 2005.

  1. Sanjay Pais

    Sanjay Pais Guest

    I am using .NET 2005 Beta 2.

    I need to create a custom property for a text box like this. My custom
    property is called ApplySecurity.

    <asp:TextBox ID="txtTextBox1" ApplySecurity="True"

    I want to add this to my tool box on the side available as a customized
    textbox whose property would apear in the html when i drop in in a form. I
    want the property also to appear in the properties box.

    Any one has any ideas how i can do this?

    thanks in advance

    Sanjay Pais, Aug 3, 2005
    1. Advertisements

  2. Sanjay Pais

    JJ_377 Guest

    I believe you need to create a custom control for this so that it could
    be added to the toolbox. I know you can then create and set properties
    for your control as you would for any class you create for example:

    I did this recently with a user control (which cannot be added to a
    toolbox*) but featuring other controls that needed properties set and
    here's how I did it: (I don't have the code with me so working from
    memory) This happens to be a text box that the user enters something in
    that is saved to a database and then the control is repopulated with
    data from the database.

    In a user control (UserControl.ascx):

    Public Property AProperty() As String
    Return Me.txtBox.text
    End Get

    Set(ByVal Value As String)
    txtBox.text = Value
    End Set
    End Property

    In the webform:

    If Not IsDBNull(drCustomer("AProperty")) Then
    UserControl.State = drCustomer("AProperty")
    End If

    I was able create and set other properties for the controls (background
    colors, borders, etc) in a simliar manner. The big problem I had and
    never got an answer for was dropdownlists...wasn't able to work with

    *Here is a MS link on developing controls:
    JJ_377, Aug 3, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.