Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use a dynamic character count script on a Textbox that's located in a Detailsview (ASP.NET)
    primarykey
    data
    text
    <p>I want to achieve a character counter that displays the number of characters you've typed in a Textbox on my webpage in ASP.NET. This Textbox is nested in a DetailsView.</p> <p>The normal solution of including (character count script)+(onkeypress for Textbox)+(Readonly input) as listed below wasn't working:</p> <p>The script:</p> <pre><code>&lt;script type="text/javascript"&gt; function textCounter(field, countfield, maxlimit) { if (field.value.length &gt; maxlimit) field.value = field.value.substring(0, maxlimit); else countfield.value = maxlimit - field.value.length; } &lt;/script&gt; </code></pre> <p>The Textbox:</p> <pre><code>&lt;asp:TextBox ID="TextBox1" runat="server" onkeyup="textCounter(TextBox1, this.DetailsView.remLen, 300);" onkeydown="textCounter(TextBox1, this.DetailsView.remLen, 300);" TextMode="MultiLine" Text='&lt;%# Bind("idea") %&gt;'&gt;&lt;/asp:TextBox&gt; </code></pre> <p>And the Input (which is in the DetailsView):</p> <pre><code>&lt;input readonly="readonly" type="text" name="remLen" value="300" /&gt; </code></pre> <p>Then I <a href="http://www.rosshawkins.net/archive/2006/12/04/asp.net-text-counter.html.aspx" rel="nofollow">found out</a> that having a Textbox nested in a DetailsView screws up the naming convention of the textbox. I tried the C# solution in that link but it couldn't work...</p> <p>How can I make this work? JQuery seems to be an answer but I have no idea where some code like <code>var Text = $("span[id$=TextBox1]");</code> would fit into my files. Need help!</p> <p>I'm working with Microsoft Visual Web Developer 2010 Express in VB (I'm a noob who uses mainly the graphic UI of the program with some programming experience on Android in Java). Wouldn't mind a C# solution if someone had one.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload