473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagrid link button click event in clientside

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
2 11594
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass =...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
5
by: ruca | last post by:
Hi, Can anyone give me examples of how can I hightlight cells of my datagrid? I know that I must use ItemBound event and probably JavaScript. The thing is that I have a anual calendar,...
7
by: Joel Reinford | last post by:
I am looking for a way to set the selectedindex of a datagrid based on the datakey value. For example given this grid with a datakey of OrderID: OrderID Item 54 A 98 ...
7
by: Rémi | last post by:
Hello. I have just gotten a client-side delete confirmation Javascript button to work, using this FAQ question as a basis (3rd question down, URL...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.