I have grid that uses EditForm for the edit mode. Inside the edit form, I have a button that sends email from the server:
<asp:Button ID="EmailButton" Text="Email" OnClick="EmailButton_Click" OnClientClick="javascript:radconfirm('Are you sure you want to send the email?', emailConfirmCallback); return false;" runat="server" /> |
the callback function for radconfirm was defined as
function emailConfirmCallback(arg) |
{ |
if (arg) |
{ |
var eButton = $find('<%# ((GridItem)Container).FindControl("EmailButton").ClientID %>'); |
eButton.click(); |
} |
} |
The problem is that $find() cannot find the button in the callback function. What shoud I do so that when OK on radconfirm was clicked, the server side function EmailButton_Click() will be executed? Thanks,
Peichung
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 01 Apr 2009, 12:23 PM
Hello Peichung,
You can refer to the following code library submission which explains how to access controls in Templates of the grid on client side:
Accessing server controls in a grid template on the client
Thanks
Princy.
You can refer to the following code library submission which explains how to access controls in Templates of the grid on client side:
Accessing server controls in a grid template on the client
Thanks
Princy.
0
0
Peichung
Top achievements
Rank 1
answered on 21 Apr 2009, 11:07 PM
I just realize that my implementation doesn't work correctly. In my FormTemplate, I have:
On the server side, I have:
The problem is that in SendEmail(), the GridEditableItem always refers to the first item in the grid. Therefore, FindControl() only works if it is the first item in the grid that fires the event. Please advise how to make it work. Thanks,
<asp:Button ID="SendEmailButton" Text="Send Email" CommandName="PerformSendEmail" OnClientClick="javascript:radconfirm('Are you sure you want to send the email?', emailConfirmCallback, 300, 100); return false;" runat="server" /> |
function emailConfirmCallback(arg) |
{ |
if (arg) |
{ |
var masterTable = $find("<%= Grid.ClientID %>").get_masterTableView(); |
masterTable.fireCommand("PerformSendEmail", ""); |
} |
else |
radalert("Email canceled.", 300, 100); |
} |
On the server side, I have:
protected void Grid_ItemCommand(object source, GridCommandEventArgs e) |
{ |
// Send email |
if (e.CommandName == "PerformSendEmail") |
{ |
SendEmail(e.Item as GridEditableItem); |
} |
} |
private void SendEmail(GridEditableItem editedItem) |
{ |
RadEditor commentEditor = editedItem.FindControl("CommentBox") as RadEditor; |
... |
} |
The problem is that in SendEmail(), the GridEditableItem always refers to the first item in the grid. Therefore, FindControl() only works if it is the first item in the grid that fires the event. Please advise how to make it work. Thanks,
0
Hi Peichung,
In this case, you can pass a second argument in the fireCommand method, which can specify the item which is raising the command. For example, you can use the ItemIndex to reflect this.
I hope this suggestion helps.
Kind regards,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
In this case, you can pass a second argument in the fireCommand method, which can specify the item which is raising the command. For example, you can use the ItemIndex to reflect this.
I hope this suggestion helps.
Kind regards,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peichung
Top achievements
Rank 1
answered on 22 Apr 2009, 02:26 PM
Could you please provide a code snippet for how to do get item index on the client side and get EditedItem on the server side? Thanks,
0
Hello Peichung,
You can use the onRowMouseOver client side handler to keep track of which row the user is at present. You can assign this value to a js variable with a global scope. Then, you can pass this as the second value of the client side method:
masterTable.fireCommand("PerformSendEmail", rowIndexVariable);
I hope this gets you started properly.
Greetings,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.