Enter key in datagrid

Discussion in 'ASP .Net Datagrid Control' started by Stephen J. Shephard, Apr 25, 2004.

  1. Hi there,
    I know this is probably a 101-type question, and I've dealt with it using
    client script blocks before, but I'm curious about what the best way to
    handle the enter key is.. (i.e., to handle it when it generates a postback).

    In my particularly frustrating situation, I have a master-detail type
    datagrid/form page, and when the user hits the enter key, the form is
    submitted and the first record in the master grid gets deleted. I'm assuming
    this is because the enter key is submitting the form and what, assuming a
    'Delete' command name or something? The only way a record can get deleted is
    by using my 'ondeletecommand' event handler.. My datagrid has four columns,
    the first being a linkcommand with an 'edit' command name, the second and
    third are simple labels, and the fourth is an image button with a 'delete'
    command name.

    Does anyone have any advice, not necessarily for the particular nuance of my
    problem, but just in general, how to handle the enter key? I've seen some
    examples on the web with people building their own datagrid controls that
    inherit from the datagrid, adding functionality to handle the enter key, but
    this is a bit much for what I'm trying to do. Surely there's a better way to
    handle the enter key than building a new control..?

    Any ideas?

    Thanks,
    S
     
    Stephen J. Shephard, Apr 25, 2004
    #1
    1. Advertising

  2. Hi Stephen,

    Based on my understanding, you want to disable the default "Enter" behavior
    for DataGrid control.

    Yes, if you press Enter in DataGrid, the first row's Button's click event
    will fire. This is the default behavior of IE and html, it has nothing to
    do with Asp.net.

    If you really want to disable this default function, you need not inherit
    this datagrid. You just need to add this statement in Page.Load event:
    DataGrid1.Attributes.Add("onkeydown","if(event.keyCode==13){event.returnValu
    e=false;}");

    This will inject javascript code to the client, which disables the default
    function.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Apr 26, 2004
    #2
    1. Advertising

  3. Thanks,
    That's essentially what I'm doing today.. Was just curious if there was a
    cool trick I might be missing out on.. Thanks for the info on the first
    row's button though, I wasn't really aware of that pattern I guess.. gives
    me some ideas on manipulating the environment for the better anyway.
    Thank again,
    S

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    > Hi Stephen,
    >
    > Based on my understanding, you want to disable the default "Enter"

    behavior
    > for DataGrid control.
    >
    > Yes, if you press Enter in DataGrid, the first row's Button's click event
    > will fire. This is the default behavior of IE and html, it has nothing to
    > do with Asp.net.
    >
    > If you really want to disable this default function, you need not inherit
    > this datagrid. You just need to add this statement in Page.Load event:
    >

    DataGrid1.Attributes.Add("onkeydown","if(event.keyCode==13){event.returnValu
    > e=false;}");
    >
    > This will inject javascript code to the client, which disables the default
    > function.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
     
    Stephen J. Shephard, Apr 26, 2004
    #3
  4. Hi Stephen,

    Thanks very much for your feedback.

    I am glad my reply makes sense to you. If you have any further question,
    please feel free to post. Thanks

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Apr 28, 2004
    #4
    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. bsm
    Replies:
    0
    Views:
    1,329
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    414
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    502
  4. Matt
    Replies:
    1
    Views:
    528
    Michael Winter
    Mar 6, 2004
  5. HopfZ
    Replies:
    0
    Views:
    597
    HopfZ
    Aug 28, 2006
Loading...

Share This Page