By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Datagrid link button click event in clientside

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.getElementsByTagN ame("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[i];
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" <NO*******************@hotmail.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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.getElementsByTagN ame("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[i];
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" <NO*******************@hotmail.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.