I have a grid inside a user control. The user control is recreated on postback. After it is recreated the NeedDataSource always fires and the rebind reason is always "InitialLoad". Also, none of my command handlers are called. Am I not supposed to be recreating the control?
This is what I'm doing:
Creating the user control with the grid inside of it.
In the NeedDataSource, I bind it to the data (and I DON'T call DataBind or Rebind())
The grid shows up fine with all data in it.
Then when I press edit, it makes the fields editable.
Once I press update (which is next to "cancel"), it posts back, the user control (that contains the grid) is recreated by me in Page_Load, and NeedDataSource is called again. The rebind reason is always "InitialLoad".
Notes:
No where am I turning off view state.
I'm using telerik version 2011.2.915.40.
The only place I'm bind to the grid is in NeedDataSource.
Any idea on what may be happening? All I'm looking to do is having a grid that has items which I can edit.
Here is my grid definition:
More markup in the user control:
Code in aspx Page_Load:
Code in user control:
This is what I'm doing:
Creating the user control with the grid inside of it.
In the NeedDataSource, I bind it to the data (and I DON'T call DataBind or Rebind())
The grid shows up fine with all data in it.
Then when I press edit, it makes the fields editable.
Once I press update (which is next to "cancel"), it posts back, the user control (that contains the grid) is recreated by me in Page_Load, and NeedDataSource is called again. The rebind reason is always "InitialLoad".
Notes:
No where am I turning off view state.
I'm using telerik version 2011.2.915.40.
The only place I'm bind to the grid is in NeedDataSource.
Any idea on what may be happening? All I'm looking to do is having a grid that has items which I can edit.
Here is my grid definition:
<telerik:RadGrid ID="radGridEmails" runat="server" Skin="Transparent" AutoGenerateColumns="false"> <MasterTableView EditMode="InPlace" > <Columns> <telerik:GridEditCommandColumn /> <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email" > </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid>More markup in the user control:
<telerik:RadAjaxManagerProxy ID="RadAjaxManager2" runat="server" > <AjaxSettings > <telerik:AjaxSetting AjaxControlID="radGridEmails" > <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="radGridEmails" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManagerProxy>Code in aspx Page_Load:
if (ViewState["currentlyLoadedSection"] != null) { panelMain.Controls.Clear(); string ctrl = (string)ViewState["currentlyLoadedSection"]; UserControl uc = (UserControl) GetControlByType(ctrl); uc.ID = ctrl; panelMain.Controls.Add(uc); Trace.Write("recreated section " + ctrl); }Code in user control:
protected override void OnInit(EventArgs e) { base.OnInit(e); radGridEmails.UpdateCommand += new Telerik.Web.UI.GridCommandEventHandler(radGridEmails_UpdateCommand); radGridEmails.InsertCommand += new Telerik.Web.UI.GridCommandEventHandler(radGridEmails_InsertCommand); radGridEmails.DeleteCommand += new Telerik.Web.UI.GridCommandEventHandler(radGridEmails_DeleteCommand); radGridEmails.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(radGridEmails_NeedDataSource); }protected void radGridEmails_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { radGridEmails.DataSource = emailAddresses; Trace.Write(e.RebindReason.ToString()); }