2

I wrote this:

<asp:TextBox ID="txtSMSMessaggio" CssClass="inputForm" MaxLength="240" TextMode="MultiLine" runat="server"></asp:TextBox> 

but on client side I can't see the attribute maxlength (which I need). Why? And how can I fix it?

2
  • 1
    edit: I see what you mean, vote revoked! Commented Sep 10, 2013 at 14:54
  • @RGraham: no that's another kind of question. I want that attributes appair on client. Commented Sep 10, 2013 at 14:55

3 Answers 3

1

Can you just use a <textarea> tag and add runat="server"?

<textarea id="txtSMSMessaggio" class="inputForm" maxlength="240" runat="server"></textarea> 
Sign up to request clarification or add additional context in comments.

3 Comments

No, because I can't use that textarea as controls in the .cs. Such as txtSMSMessaggio.Text
Declaring a <textarea> with a runat=server attribute will give you access to a HtmlTextArea in the code-behind. Not a 1-to-1 map, but still gives you access to the control.
You need to use txtSMSMessaggio.Value instead
1

you might not be interested in counting the characters in the TextBox, but its helpful to let the end user know there is a limit before it is reached. you can do something like

<script language="javascript" type="text/javascript"> var Maxlength = 240; function taLimit() { var srcObject = event.srcElement; if (srcObject.value.length == Maxlength * 1) return false; } function taCount(tagName) { var srcObject = event.srcElement; if (srcObject.value.length > Maxlength * 1) srcObject.value = srcObject.value.substring(0, Maxlength * 1); if (tagName) visCnt.innerText = Maxlength - srcObject.value.length; } </script> <asp:TextBox ID="txtSMSMessaggio" CssClass="inputForm" TextMode ="MultiLine" runat="server" onkeypress="return taLimit()" onkeyup="return taCount(Counter)" onfocus="return taCount(Counter)" ></asp:TextBox><br /> (<span id="Counter">240</span> characters left)<br /> 

Comments

0

You can try a Regular Expression to restrict the user to 240 characters:-

<asp:RegularExpressionValidator runat="server" ID="txtSMSMessaggio" ControlToValidate="txtInput" ValidationExpression="^[\s\S]{0,240}$" ErrorMessage="Some error message" Display="Dynamic">*</asp:RegularExpressionValidator> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.