this is the aspx code for my ASPxGridView
<dx:ASPxGridView ID="dgJournalList" runat="server" ClientInstanceName="dgJournalList"
OnCustomCallback="dgJournalList_CustomCallback"
OnCustomJSProperties="dgJournalList_CustomJSProperties"
KeyFieldName="LineNo" AutoGenerateColumns="False">
<SettingsPager Visible="False">
</SettingsPager>
<SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" />
<Columns>
<dx:GridViewDataTextColumn FieldName="ItemNo" VisibleIndex ="1"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="PostingDateStr" VisibleIndex ="2"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="EntryTypeStr" VisibleIndex ="3"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="DocumentNo" VisibleIndex ="4"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="LocationCode" VisibleIndex ="5"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Qty" VisibleIndex ="6"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="UOM" VisibleIndex ="7"
ReadOnly="true" Visible="true">
</dx:GridViewDataTextColumn>
</Columns>
<ClientSideEvents EndCallback ="onEndCallback(s, e)" />
</dx:ASPxGridView>
the function from javascript
onButtonClick = function (args)
{
switch (args)
{
case 'refresh':
dgJournalList.PerformCallback('Refresh');
break;
}
}
and the method for callback
protected void dgJournalList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
{
string[] param = e.Parameters.Split(separator, StringSplitOptions.None);
BOResponse objResponse = new BOResponse();
switch (param[0])
{
case "Refresh":
objResponse = GetListJournal(null);
if (objResponse.MsgCode != 0)
{
dgJournalList.JSProperties["cpErrMsg"] = objResponse.MsgDesc;
}
dgJournalList.DataSource = JournalList;
dgJournalList.DataBind();
dgJournalList.FocusedRowIndex = 0;
break;
}
}
When performing the refresh action, my application doesn't call back, doing the postback instead, as, when debugging, the breakpoint at the callback method isn't reached; it's hitting a breakpoint at Page_Load
method.
Where is my code failing?
what you see is a normal behavior. Postback means complete page reload. Do you observe it your case? Based on the code you've posted you should't. You should see only the grid area reload.
Page_Init
and Page_Load
events will be fired after you've called dgJournalList.PerformCallback('Refresh');
in Javascript. Then the control will be handed to your dgJournalList_CustomCallback
method.
If you don't want the Page_Init
and Page_Load
logic be executed during grid's custom callback, then add the following checks into those event handlers:
if (!IsPostBack && !IsCallback)
{
// your code which is run ONLY at initial page load should be put here
}
If you need to run Page_Init and Page_Load code during some button clicks which do cause postback, then remove the IsPostBack
part from the above condition.
More info on the topic: