GridView/FormView Issue

P

pbarbalias

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
 
B

Bruno Alexandre

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.

--

Bruno Alexandre
Stroby, Danmark

"a Portuguese in Denmark"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top