Datagrid link button click event in clientside

N

Niclas Lindblom

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
 
R

Rick Spiewak

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;
}
}
}
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top