Last post Jan 07, 2009 11:36 PM by Nai-Dong Jin - MSFT
Jan 05, 2009 08:06 AM|sebastianpereira|LINK
I'm building a server control that derives from TextBox that will include validators along with it.
The problem that I'm facing now is the properties assigment. Placing the control in a web form, and setting the properties in the designer (not in the Form Designer but in the HTML designer) causes the control to not take the values of the properties.
<!-- Default.aspx -->
<!-- Integer Validation -->
<cc1:TextBoxX ID="txtQuantity" runat="server" ToolTip="int(10,0) validation with regular expression, not required"
TooTip, which is a TextBox property is assigned to the resulting control, but "IsRequired", "ErrorDisplay" and the other not.
The only way to get this working is through the code behind, assigning with code in the Page_Load event:
txtQuantity.IsRequired = True
txtQuantity.ErrorDisplay = ValidatorDisplay.Dynamic
txtQuantity.FieldName = "Quantity"
txtQuantity.DataType = TextBoxX.TextBoxDataType.tdtInteger
txtQuantity.Precision = 10
This is the way that the properties works inside the extended control, for example, "FieldName":
Public Property FieldName() As String
Dim obj As Object = Me.ViewState.Item(Me.UniqueID & "FieldName")
If (Not obj Is Nothing) Then
Set(ByVal value As String)
Me.ViewState.Item(Me.UniqueID & "FieldName") = value
To add more information to the problem, in the method OnInit, all the properties are initialized with the required values:
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
Me.ErrorMessageRegularExpressionValidator = String.Empty
Me.FieldName = Me.ID
In the PreRender overrided method, the control is rendered with validator controls, which are assigned with the extended text box properties (like FieldName).
Hope my problem statement was clear enough and that somebody can give me some light on this.
Thank you very much!
asp.NET 2.0 VB user control
Jan 07, 2009 11:36 PM|Nai-Dong Jin - MSFT|LINK
Do you mean that if you assign your property values in source code, it doesn't work, but if you assign it in code-behind it works, right?
I've performed a test on my side and it works as expected. Here, what i can suggest is try to attach your control library project, and add a breakpoint in your custom server control, assign your property in source mode, run it step by step, try to check
if it comes into the set/get block. Also, you can provide more code information for us to investigate.