GridView/FormView Issue

Discussion in 'ASP .Net Datagrid Control' started by pbarbalias, Feb 8, 2007.

  1. pbarbalias

    pbarbalias Guest

    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
    pbarbalias, Feb 8, 2007
    #1
    1. Advertising

  2. 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"


    "pbarbalias" <> wrote in message
    news:...
    > 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, Feb 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. P. Yanzick

    FormView Edit Template Issue

    P. Yanzick, Feb 3, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    6,626
    P. Yanzick
    Feb 7, 2006
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,947
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    506
    Chris
    May 19, 2007
  4. Cirene
    Replies:
    1
    Views:
    372
    gnewsgroup
    Nov 4, 2007
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    623
    David Thielen
    Jun 16, 2006
Loading...

Share This Page