Datagrid link button click event in clientside

Discussion in 'ASP .Net' started by Niclas Lindblom, Jun 26, 2004.

  1. Hi,

    I have a datagrid with linkbuttons. I would like to catch the click event
    when a link button has been clicked and use the string from the text value
    of the link button in a clientside Java script. Is this possible or should I
    look for other ways of achieving this ?

    Regards

    Niclas
     
    Niclas Lindblom, Jun 26, 2004
    #1
    1. Advertising

  2. Niclas Lindblom

    Rick Spiewak Guest

    This is possible. Here is a related example, which uses the onclick event of
    a checkbox:

    // Enable or disable the one or more validation control(s), based on the
    state of the calling control.
    // The calling control is an ASP.NET control which is a child control
    within a DataGridItem or equivalent,
    // using the onclick event on the client. This implementation assumes that
    the calling control is a checkbox.
    //
    // Author: Rick Spiewak, 6/23/2004
    //
    // Usage:
    // In the HTML of the .aspx page, reference this file:
    //
    // <script language="javascript" src="[relative path to this file:
    Utilities.js]" ></script>
    //
    // Example of use during the ItemCreated event:
    // Dim itm As DataGridItem = e.Item
    // Dim enableValidation As String =
    "enableValidation(this,'valManifestNo, valAnotherControl');"
    // Select Case itm.ItemType
    // Case ListItemType.Item, ListItemType.AlternatingItem
    // Dim cb As CheckBox =
    DirectCast(itm.FindControl("chkReceive"), CheckBox)
    // cb.Attributes.Add("onclick", enableValidation)
    // End Select
    //
    // Parameters:
    // ctrl a datagrid item (or similar) child control. Currently, this must
    be a checkbox.
    // The name is parsed to find the line prefix.
    // validator the ASP.NET ID (string) of the validation control(s) to be
    enabled or disabled
    // This can be a comma-separated list.
    function enableValidation(ctrl, validator)
    {
    validator = validator.replace(" ","");
    var i = validator.indexOf(",");
    // Handle the case where "validator" is a comma-separated list by
    recursion.
    if (i > -1) {
    var valArray;
    var j;
    valArray = validator.split(",");
    for (j = 0; j < valArray.length; j++) {
    enableValidation(ctrl,valArray[j]);
    }
    return(0);
    }
    if (validator.length < 2){return(0);}

    var ID = ctrl.id;
    i = ID.indexOf("__");
    i = ID.indexOf("_", i + 2);
    var validatorID = ID.substring(0,i) + "_" + validator;
    // The validator is in a span, potentially in a different table cell
    // the parentElement is a <td>, its parent is the <tr>
    var spans =
    ctrl.parentElement.parentElement.getElementsByTagName("span");
    // Find the validator for *this* item among the spans
    // currently only implemented for checkbox controls as the input
    control
    for (i = 0; i < spans.length; i++) {
    var val = spans;
    if (val.id == validatorID) {
    // Set the initial state as enabled, then call the standard
    validation
    // function to get the correct value of .isvalid
    val.setAttribute("enabled",true);
    ValidatorValidate(val);
    // If the checkbox is checked and the validator isn't valid,
    then show the error
    val.style.visibility = (ctrl.checked && !val.isvalid) ?
    "visible" : "hidden";
    val.setAttribute("enabled",ctrl.checked);
    break;
    }
    }
    }
    "Niclas Lindblom" <> wrote in message
    news:...
    > Hi,
    >
    > I have a datagrid with linkbuttons. I would like to catch the click event
    > when a link button has been clicked and use the string from the text value
    > of the link button in a clientside Java script. Is this possible or should

    I
    > look for other ways of achieving this ?
    >
    > Regards
    >
    > Niclas
    >
    >
     
    Rick Spiewak, Jun 27, 2004
    #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. Purvi T
    Replies:
    0
    Views:
    926
    Purvi T
    Oct 19, 2004
  2. jorge
    Replies:
    2
    Views:
    1,340
    jorge
    May 26, 2004
  3. Amy
    Replies:
    0
    Views:
    1,031
  4. Max2006
    Replies:
    2
    Views:
    1,637
    Walter Wang [MSFT]
    Sep 19, 2007
  5. jorge
    Replies:
    1
    Views:
    447
    Teemu Keiski
    May 28, 2004
Loading...

Share This Page