Hi,
I am developing an Mp3 Player for my site, using telerik rad ajax controls. A requirement I have is to bind the song titles and their paths (They are dictionary <TKey, TString> collection). However, I need to get the clicked row's song path title to pass to the mp3 player code to then play that song.
I have used the API quite heavily and I know how to do this (get value of a cell on clicking a row), but with the client side API, I can't pass the value of a cell to a C# function - or can I?
Thanks
I am developing an Mp3 Player for my site, using telerik rad ajax controls. A requirement I have is to bind the song titles and their paths (They are dictionary <TKey, TString> collection). However, I need to get the clicked row's song path title to pass to the mp3 player code to then play that song.
I have used the API quite heavily and I know how to do this (get value of a cell on clicking a row), but with the client side API, I can't pass the value of a cell to a C# function - or can I?
Thanks
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 08 Jun 2009, 07:23 AM
Hi,
You may access the clicked row's cell value on the client and then pass it to the server side in the RaisePostBackEvent event as shown below.
ASPX:
CS:
Thanks
Shinu
You may access the clicked row's cell value on the client and then pass it to the server side in the RaisePostBackEvent event as shown below.
ASPX:
<script type="text/javascript"> |
function RowClick(sender, eventArgs) |
{ |
var grid = sender; |
var MasterTable = grid.get_masterTableView(); |
var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; |
//to access the cell value on the client |
var cell = MasterTable.getCellByColumnUniqueName(row, "ProductName"); |
//pass the cell value to the server side |
__doPostBack("<%= RadGrid1.UniqueID %>", "CellValue:" + cell.innerHTML); |
} |
</script> |
CS:
protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument) |
{ |
base.RaisePostBackEvent(source, eventArgument); |
if (source == RadGrid1 && eventArgument.IndexOf("CellValue") != -1) |
{ |
string cellvalue = eventArgument.Split(':')[1].ToString(); |
// you can pass the cell value to desired function |
} |
} |
Thanks
Shinu
0
G S S
Top achievements
Rank 1
answered on 08 Jun 2009, 02:42 PM
Hi,
Thanks for that. I'm still confused how to use that code though.
I will call the javascript function in the onrowclick event (in clientSettings) and write that C# code in the codebehind (obviously). So when that javascript function's __doPostBack line is triggered, that will cause a postback (I've noticed that ASP.NET writes this code in my markup too), and will the C# event then automatically execute?
Also, if there is a postback setting in the grid, will this have to be on? What if I want to do this partially with no postback (AJAX style)?
Thanks
Thanks for that. I'm still confused how to use that code though.
I will call the javascript function in the onrowclick event (in clientSettings) and write that C# code in the codebehind (obviously). So when that javascript function's __doPostBack line is triggered, that will cause a postback (I've noticed that ASP.NET writes this code in my markup too), and will the C# event then automatically execute?
Also, if there is a postback setting in the grid, will this have to be on? What if I want to do this partially with no postback (AJAX style)?
Thanks
0
Princy
Top achievements
Rank 2
answered on 09 Jun 2009, 11:20 AM
Hello,
You can try using the AjaxManager and pass the cell value in its AjaxRequest event which is automatically fired as shown below. When using this method you need not enable any postback setting in the grid.
aspx:
js:
c#:
Thanks
Princy.
You can try using the AjaxManager and pass the cell value in its AjaxRequest event which is automatically fired as shown below. When using this method you need not enable any postback setting in the grid.
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" EnableAJAX="true" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
js:
function RowClick(sender, eventArgs) |
{ |
var grid = sender; |
var MasterTable = grid.get_masterTableView(); |
var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; |
var cell = MasterTable.getCellByColumnUniqueName(row, "ColumnUniqueName"); |
$find("<%=RadAjaxManager1.ClientID%>").ajaxRequest(cell.innerHTML); |
} |
c#:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) |
{ |
} |
Thanks
Princy.
0
G S S
Top achievements
Rank 1
answered on 10 Jun 2009, 11:08 PM
Princy,
Everytime the js function executes, does the c# function then execute? Would I cast "e" (of its ajaxrequesteventargs type) to a string to get the relevant cell name?
Thanks
Everytime the js function executes, does the c# function then execute? Would I cast "e" (of its ajaxrequesteventargs type) to a string to get the relevant cell name?
Thanks
0
Princy
Top achievements
Rank 2
answered on 11 Jun 2009, 04:52 AM
Hello,
On calling the ajaxRequest client method, the server side event is triggered immediately. Thereby, to access the cell value on the server side, you can try the following code:
c#:
Thanks
Princy.
On calling the ajaxRequest client method, the server side event is triggered immediately. Thereby, to access the cell value on the server side, you can try the following code:
c#:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) |
{ |
string strtxt = e.Argument; |
} |
Thanks
Princy.