Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Namshub #1
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
-
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... -
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... -
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... -
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... -
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... -
Teemu Keiski #2
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



Reply With Quote

