Hi to all.. I am new in asp.net 2..
I have a table with 3 fields. First name, Last Name, Description.
I've created a GridView page to show list of them and provide insert,
update, delete.
So far everything ok. When I click on a row, with FormView I have a
small popup and show
the fields there. For Description I have a multiline text box (like a
textarea) so the user can write
up to 300 characters.
My problem is:
1) How can I have a label on this pop-up form, and after the page is
loaded, I could count the number
of characters and show it.
2) How I can count the characters being typed or deleted?
3) How I can enforce the user to write at least 100 characters or not
more than 200?
Any comments are welcome..
Thanks in advance for your time..
PB
that you should perform with Javascript
lets say that you have a DIVwith the name divCount
and that multiline textbox is called txtDescription
on Page_Load event you need to ADD a javascript to the textbox so it will
perform an action everytime the user writes a letter or deletes a letter,
for that you add in the Page_Load this:
txtDescription.Attributes.Add("onkeyup","countLetters();")
txtDescription.Attributes.Add("onkeydown","countLetters();")
in the ASPX page you need to crate the Javascript Function that will count
and tell the Label the exact letter count.
<script type="text/javascript">
var min = 10;
var max = 15;
function countLetters() {
var descr = document.getElementById('<%= txtDescription.ClientID
%>');
var label = document.getElementById('lblCount');
if ( descr.value.length < min ) {
label.innerHTML = 'you wrote <strong>' + descr.value.length
+ '</strong> letters so far, you need to write more ' + (min -
descr.value.length ) + ' letters.';
}
if ( descr.value.length >= min && descr.value.length < max) {
label.innerHTML = 'you wrote <strong>' + descr.value.length
+ '</strong> letters so far, you have more ' + (descr.value.length - min) +
' letters than the needed, but feel free to write until ' + max + '
letters.';
}
if ( descr.value.length > max ) {
label.innerHTML = 'the limit is ' + max + ' letters!';
descr.value = descr.value.substring(0, max);
}
}
</script>
Now, to enforce the user to update more than the minimum characters, all you
need is to validate before update,
let's image that you have a linkButton called lnkUpdate that will fire an
event in the ASPX page to update thoose values in the popup box to the
database:
again in the Page_Load event
lnkUpdate.Attributes.Add("onclick","return validate();")
below the countLetters function, write:
function validate() {
var descr = document.getElementById('<%= txtDescription.ClientID %>');
if (descr.value.length < min ) {
alert('the minimum is ' + min + ' letters, you only wrote ' +
descr.value.length + ' letters');
return false;
} else {
return true;
}
}
this will send FALSE if the textbox has less chars than the minimum, and
sending FALSE the update link will not fire!
hope this helps.

Signature
Bruno Alexandre
Stroby, Danmark
"a Portuguese in Denmark"
> Hi to all.. I am new in asp.net 2..
>
[quoted text clipped - 21 lines]
>
> PB