Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / February 2007

Tip: Looking for answers? Try searching our database.

GridView/FormView Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pbarbalias - 08 Feb 2007 19:52 GMT
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
Bruno Alexandre - 14 Feb 2007 21:36 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.