Hello,
1. I want to trigger an onclick method in the c# code-behind when the AccountNumber is clicked. I cannot find an attribute or such an event to trigger an onclick method.
Thanks
1. I want to trigger an onclick method in the c# code-behind when the AccountNumber is clicked. I cannot find an attribute or such an event to trigger an onclick method.
<
telerik:GridHyperLinkColumn
DataNavigateUrlFields
=
"ID"
DataNavigateUrlFormatString
=
"Page.aspx?id={0}"
DataTextField
=
"AccountNumber"
HeaderText
=
"Account Number"
UniqueName
=
"AccountNumber"
>
Thanks
8 Answers, 1 is accepted
0
Accepted

Jayesh Goyani
Top achievements
Rank 2
answered on 06 Aug 2011, 06:14 AM
Hello ,
You can achieve by below code.
Note : You can also use HyperLink in place of LinkButton.
let me know if any concern.
Thanks,
Jayesh Goyani
You can achieve by below code.
<
MasterTableView
DataKeyNames
=
"ID"
>
...............
...............
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"btnlnk"
runat
=
"server"
Text='<%# Eval("Name") %>' OnClick="btnlnk_Click"
></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected
void
btnlnk_Click(
object
sender, EventArgs e)
{
LinkButton btnlnk = sender
as
LinkButton;
GridDataItem item = btnlnk.NamingContainer
as
GridDataItem;
int
ID = Convert.ToInt32(item.GetDataKeyValue(
"ID"
));
// do your functinality
}
Note : You can also use HyperLink in place of LinkButton.
let me know if any concern.
Thanks,
Jayesh Goyani
0

Princy
Top achievements
Rank 2
answered on 08 Aug 2011, 05:46 AM
Hello,
You can attach "onclick" event to GridHyperLinkColumn in ItemDataBound event as shown below.
C#:
Thanks,
Princy.
You can attach "onclick" event to GridHyperLinkColumn in ItemDataBound event as shown below.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
HyperLink link = (HyperLink)dataItem[
"AccountNUmber"
].Controls[0];
int
index = dataItem.ItemIndex;
link.Attributes.Add(
"onclick"
,
"window.radopen(\"Grid.aspx"
+ index +
"\",\"NewWindow\"); return false;"
);
}
}
Thanks,
Princy.
0

f
Top achievements
Rank 1
answered on 09 Aug 2011, 07:05 PM
Jayesh your method with the LinkButton inside the GridTemplateColumn worked beautifully.
Thank you very much!
Princy . . . I ran into problems with your approach so I quickly abandoned it, but thanks for your help.
Thank you very much!
Princy . . . I ran into problems with your approach so I quickly abandoned it, but thanks for your help.
0

TonyG
Top achievements
Rank 1
answered on 28 Oct 2011, 02:56 AM
Can someone elaborate on this? I'm not understanding how this works, but it looks powerful.
When a user clicks a link in a cell, I want to launch another window or tab on the client, and I want a postback to notify the server that the user clicked a specific link. Since the page is launching in another window with Target="_blank", I expect we can get both the postback as well as the new (unrelated) page.
The code that Princy provides would be OK but I'm not sure in the event cycle how to adjust that window.radopen to invoke a postback on the current page.
And in the code that Jayesh provides, if I use a GridHyperLinkColumn there is no postback (?right?), but if I use a linkbutton there is no launch of a new page.
I guess I don't know if clicking a control should get Javascript to launch the new window, or if clicking a hyperlink should get Javascript to cause a postback.
Thanks!
When a user clicks a link in a cell, I want to launch another window or tab on the client, and I want a postback to notify the server that the user clicked a specific link. Since the page is launching in another window with Target="_blank", I expect we can get both the postback as well as the new (unrelated) page.
The code that Princy provides would be OK but I'm not sure in the event cycle how to adjust that window.radopen to invoke a postback on the current page.
And in the code that Jayesh provides, if I use a GridHyperLinkColumn there is no postback (?right?), but if I use a linkbutton there is no launch of a new page.
I guess I don't know if clicking a control should get Javascript to launch the new window, or if clicking a hyperlink should get Javascript to cause a postback.
Thanks!
0

Princy
Top achievements
Rank 2
answered on 28 Oct 2011, 05:27 AM
Hello TonyG,
The client function "onclick" is being called from server side for passing parameters. Jayesh's code explains how to find the row using NamingContainer property which will directly give the DataKeyValue. Inorder to pass parameters from server side we can explicitly handle the onclick event as explained in the code.
Thanks,
Princy.
The client function "onclick" is being called from server side for passing parameters. Jayesh's code explains how to find the row using NamingContainer property which will directly give the DataKeyValue. Inorder to pass parameters from server side we can explicitly handle the onclick event as explained in the code.
Thanks,
Princy.
0

TonyG
Top achievements
Rank 1
answered on 29 Oct 2011, 12:55 AM
Princy, thanks for the response but....
No, the client function "onclick" is NOT being Called from the server side. You're adding the onclick handler from the server side. When the hyperlink is clicked that will cause client side activity, but not a postback to the server.
Jayesh's code describes how to send the value of field X back when the user clicks field Y (the LinkButton in the ItemTemplate). His sample causes a postback but does not launch a URL like a hyperlink will.
I'm looking to launch a URL from the client to Target="_blank" (perhaps using onclick and window.open rather than window.radopen) AND postback to the server.
Thanks to anyone who can help. And please don't hesitate to slap me around if I'm missing something obvious. Maybe LinkButton or HyperLink do have a client-side onclick as well as a post back to the server.
No, the client function "onclick" is NOT being Called from the server side. You're adding the onclick handler from the server side. When the hyperlink is clicked that will cause client side activity, but not a postback to the server.
Jayesh's code describes how to send the value of field X back when the user clicks field Y (the LinkButton in the ItemTemplate). His sample causes a postback but does not launch a URL like a hyperlink will.
I'm looking to launch a URL from the client to Target="_blank" (perhaps using onclick and window.open rather than window.radopen) AND postback to the server.
Thanks to anyone who can help. And please don't hesitate to slap me around if I'm missing something obvious. Maybe LinkButton or HyperLink do have a client-side onclick as well as a post back to the server.
0

Jayesh Goyani
Top achievements
Rank 2
answered on 29 Oct 2011, 09:01 AM
Hello,
Note : you can also use "ScriptManager.RegisterStartupScript" inplace of "Page.ClientScript.RegisterStartupScript"
Thanks,
Jayesh Goyani
<
MasterTableView
DataKeyNames
=
"ID"
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"btnlnk"
runat
=
"server"
Text='<%# Eval("Name") %>' OnClick="btnlnk_Click"
></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected
void
btnlnk_Click(
object
sender, EventArgs e)
{
LinkButton btnlnk = sender
as
LinkButton;
GridDataItem item = btnlnk.NamingContainer
as
GridDataItem;
int
ID = Convert.ToInt32(item.GetDataKeyValue(
"ID"
));
string
alertscript =
"<script language='javascript'>window.open('www.microsoft.com');</script>"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
"popupscipt"
, alertscript);
}
Note : you can also use "ScriptManager.RegisterStartupScript" inplace of "Page.ClientScript.RegisterStartupScript"
Thanks,
Jayesh Goyani
0

Mike McMillan
Top achievements
Rank 1
answered on 11 Nov 2011, 01:37 AM
Just what I need.
Thanks Jayesh !
Thanks Jayesh !