Execute jquery after ASPXGridview updated event Callback
Hi I'm working with DevExpress gridview and on updated event I have to return end user dialog message with the information about updated record
protected void AspxGrid_RowUpdated(object sender, ASPxDataUpdatedEventArgs e)
{
//After updated return some info on client side as modal window for example
}
Is there any built in functio开发者_如何学编程nality to achieve desired output, or any other sufficient way to do it??
To pass the information to the client side, you should implement 2 different steps: 1) add a new item to the ASPxGridView's JSProperties collection which will contain the required info:
ASPxGridView1.JSProperties.Add("cpInfo", "hi from server");
2) handle the ASPxGridView's client side EndCallback event to show this message:
EndCallBack = "function(s,e) {
if(typeof(s.cpInfo) != 'undefined')
alert(s.cpInfo);
}"
Edit: Here is the complete code which works here:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
KeyFieldName="CategoryID" OnRowUpdated="ASPxGridView1_RowUpdated">
<ClientSideEvents EndCallback="function(s, e) {
if(typeof(s.cpInfo) != 'undefined')
alert(s.cpInfo);
}" />
protected void ASPxGridView1_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e) {
(sender as ASPxGridView).JSProperties["cpInfo"] = "hi from server";
}
You can't directly cause a client event from a server event. But there are a number of different ways to achieve the goal, the best one depends on the situation. A few possibilities...
1) Capture the client event that occurs after an async postback (if you're using partial postbacks). Google Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded
2) Insert a client script in code, which will be run after the page load is completed, e.g.
ScriptManager.RegisterStartupScript("someJavascriptFunction();");
(that is pseudocode - there are other parameters you need to include)
3) Render something during your server event that will trigger a client event when the page is done loading. Assuming you are using jQuery and $(document).ready()
(and NOT using partial postbacks) you could set a hidden field value, and then check that value from the startup script on the client and take whatever action you want based on it.
If you're using updatepanels, you will have to do #1 or #2 - because document.ready
startup code will not re-run after a partial postback.
Please refer to the The Concept of Callbacks KB article regarding this issue. I hope it will help you.
精彩评论