Hi,
I have a grid that has its datasource set server-side.
I have added a GridButtonColumn. What i want to do is instead of when the button is clicked going to the server-side _ItemCommand of the grid, i want it to run a javascript function client-side...
Is this possible ? here is my GridButtonColumn code...
I have a grid that has its datasource set server-side.
I have added a GridButtonColumn. What i want to do is instead of when the button is clicked going to the server-side _ItemCommand of the grid, i want it to run a javascript function client-side...
Is this possible ? here is my GridButtonColumn code...
<
Columns><telerik:GridButtonColumn Text="View" CommandName="View"></telerik:GridButtonColumn></Columns>
Thanks
Mark
4 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 May 2008, 10:24 AM
Hi Mark,
Can you try with the following approach.
ASPX:
CS:
JS:
Princy.
Can you try with the following approach.
ASPX:
| <telerik:GridButtonColumn HeaderText="ButtonCol" Text="Click" UniqueName="ButtonCol" ></telerik:GridButtonColumn> |
CS:
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem item = (GridDataItem)e.Item; |
| string strKey = item.GetDataKeyValue("ProductName").ToString(); |
| LinkButton btn = (LinkButton)item["ButtonCol"].Controls[0]; |
| btn.Attributes.Add("OnClick", "return Clicked('" + strKey + "');"); |
| } |
| } |
JS:
| <script type="text/javascript" language="javascript" > |
| function Clicked(strKey) |
| { |
| alert(strKey) |
| } |
| </script> |
Princy.
0
Mark
Top achievements
Rank 1
answered on 16 May 2008, 10:34 AM
Wow ! That works great ! Thanks...
one little thing though,.. when i select the grid button, it IS running the javascript, BUT.. it is forcing a postback... can i stop this ??
Many Many Thanks
Mark :-)
one little thing though,.. when i select the grid button, it IS running the javascript, BUT.. it is forcing a postback... can i stop this ??
Many Many Thanks
Mark :-)
0
Shinu
Top achievements
Rank 2
answered on 16 May 2008, 12:23 PM
Hi Mark,
Try the following JavaScript code to prevent the PostBack.
JS:
Shinu.
Try the following JavaScript code to prevent the PostBack.
JS:
| <script type="text/javascript" language="javascript" > |
| function Clicked(strKey) |
| { |
| alert(strKey); |
| return false; |
| } |
| </script> |
Shinu.
0
Mark
Top achievements
Rank 1
answered on 16 May 2008, 12:25 PM
ah... i missed the obvious !!
Gotta say guys, your support is very impressive.
Many Thanks.... again !
Mark
Gotta say guys, your support is very impressive.
Many Thanks.... again !
Mark