Property Not saved in Composite Control... Help & Pointers required.

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

  1. #1

    Default Property Not saved in Composite Control... Help & Pointers required.

    I have created a coposite control, consisting of text, labels , radiobuttons
    and checkboxes the purpose is to create a generic control to manage user
    accounts both as an admin and as a user. I have a property that tells me
    wether they are adding a new user or modifying a current one.

    a snippet is bellow:

    Public Class UserAccount
    Inherits UserControl
    ....
    Private _DataMode As DataModeType
    ....
    Public Property DataMode() As DataModeType
    Get
    Return _DataMode
    End Get
    Set(ByVal Value As DataModeType)
    _DataMode = Value
    End Set
    End Property

    Firstly how do i reference the user control on the form, once i've dragged
    it onto the page?
    I added manually the following is this correct?
    Protected WithEvents useraccount1 As CWT2005.UserAccount

    Now this does give me access to the comoponents, properties and methods, as
    i've managed to set the property (via running the debugger), but when i call
    the save method. (using a new button, sets the visiblity to true, and sets
    the property to "New" (datamodetype))

    UserAccount1.SaveValues()

    and check the useraccount.datamode its defaulted back to "Edit"
    (DatamodeType)

    Can someone tell me what i'm doing wrong? The Useraccount1 control has
    enabledviewstate = true. But do i have to include within the property code
    adding and reading from viewstate? As i thought all properties would do
    this automatically.

    Thanks.




    Namshub Guest

  2. Similar Questions and Discussions

    1. Composite Control with FormView property tag prefix attribute?
      Hi, I've developed a Composite control designed to take one FormView and one SqlDataSource as properties. I can add my composite control to the...
    2. Losing Composite Control property that another Composite Control ...
      Hi, I'm creating 2 composite controls in ASP.net. Control 1 is a Search control and control 2 is a Map control. I have added a property...
    3. Composite control with dynamic controls depending on a property value
      Hi, all. I am really stuck here. I've written a few composite controls before and fully understand the "typical" scenarios. However, this one is...
    4. Composite Control Property Setting Problem
      I have built a simple composite control that consists of a textbox, requiredfieldvalidator and rangevalidator. For properties that are unique to...
    5. Required field validators do not while editing a row in a datagrid present in a composite control
      Hi All, I have created a composite control and I have added a datagrid in it. I am dynamically adding an edit column for editing the data. Now I...
  3. #2

    Default Re: Property Not saved in Composite Control... Help & Pointers required.

    Hi,

    so that the proeprty value would be saved over postbacks, property should
    use UserControl's ViewState collection as storage. Like this:

    Public Property DataMode() As DataModeType
    Get
    If ViewState("DataMode") Is Nothing Then
    Return DataModeType.<PutDefaultValueHere>
    Else
    Return CType(ViewState("DataMode"),DataModeType)
    End If
    End Get
    Set(ByVal Value As DataModeType)
    ViewState("DataMode") = Value
    End Set
    End Property

    And to answer your question, no properties do not use ViewState
    automatically unless they have been developed to do so. MS has built this
    into premade controls (they also use ViewState but internally) but for your
    own controls, you need to do this manually.

    Yes, control declaration is correct. It works similarly as you see it
    working with built-in controls and their declarations.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU

    "Namshub" <Richard._NoSpam_ForME_Pullen@Southend.nhs.uk> wrote in message
    news:urWjQssAFHA.1396@tk2msftngp13.phx.gbl...
    >I have created a coposite control, consisting of text, labels ,
    >radiobuttons and checkboxes the purpose is to create a generic control to
    >manage user accounts both as an admin and as a user. I have a property
    >that tells me wether they are adding a new user or modifying a current one.
    >
    > a snippet is bellow:
    >
    > Public Class UserAccount
    > Inherits UserControl
    > ...
    > Private _DataMode As DataModeType
    > ...
    > Public Property DataMode() As DataModeType
    > Get
    > Return _DataMode
    > End Get
    > Set(ByVal Value As DataModeType)
    > _DataMode = Value
    > End Set
    > End Property
    >
    > Firstly how do i reference the user control on the form, once i've dragged
    > it onto the page?
    > I added manually the following is this correct?
    > Protected WithEvents useraccount1 As CWT2005.UserAccount
    >
    > Now this does give me access to the comoponents, properties and methods,
    > as i've managed to set the property (via running the debugger), but when i
    > call the save method. (using a new button, sets the visiblity to true, and
    > sets the property to "New" (datamodetype))
    >
    > UserAccount1.SaveValues()
    >
    > and check the useraccount.datamode its defaulted back to "Edit"
    > (DatamodeType)
    >
    > Can someone tell me what i'm doing wrong? The Useraccount1 control has
    > enabledviewstate = true. But do i have to include within the property
    > code adding and reading from viewstate? As i thought all properties would
    > do this automatically.
    >
    > Thanks.
    >
    >
    >
    >

    Teemu Keiski 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