I have been trying to develop some user controls, one being a text edit control in which I set the MaxLength attribute of an ASPxTextBox control. This would seem fairly straight forward to me but VS2010 doesn’t seem to like it.
The script behind me user control is as follows
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FieldEditTextMedium.ascx.cs" Inherits="COGS.Controls.DataControls.FieldEditTextMedium" %>
<link rel="Stylesheet" href="../../CSS/FieldIndicators.css" type="text/css" media="screen" />
<table><tr><td class="FieldHeader">
<dx:ASPxLabel CssPostfix="CogsForm" ID="TextHeaderLabel" runat="server" OnLoad="Header_Load" Text='<%= this.HeaderTitle %>'/>
</td><td class="FieldEdit">
<dx:ASPxTextBox
ID="TextValueEdit"
runat="server"
Text='<%= this.FieldValue.ToString() %>' MaxLength='<%= this.MaxChars %>' />
</td></tr></table>
When I attempt to implement it I add the control to the web.config but it will not appear using intellisense however when I remove the MaxLength attribute from the code my user control will appear as normally expected.
This implies to me that this deceleration is causing an error and the control is failing to compile… or something like that. I am assuming it is something to do with using an integer as it works fine with strings.
At present I use a bit of javascript to set the maxlength on init as this doesn’t seem to cause any issues but to me seems like more work than necessary.
Also when I say it will “appear” this is usually after some messing around with closing and re-opening documents and re-building the solution which I find very frustrating.
If anyone can also provide info on how to best handle the refresh of user controls in intellisense I would be most grateful.
Normally, setting a control’s properties declaratively with “<%= %>” is not valid. You might try setting them from code behind (or perhaps with a databinding expression, if it’s appropriate: <%# %>)