This is a migrated thread and some comments may be shown as answers.

Add new Item,edit is causing postback

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 04 Dec 2012, 05:50 AM
Hi,
I am using the "RadControls for ASP.NET AJAX Q3 2012" in Sharepoint 2010.
I have added the Rad Grid and also added the ajax. However, when i click "add new item" or edit items in the grid, the grid is doing a postback. I have added the below code:

<div>       
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
  
    <telerik:RadGrid ID="RadGrid1" runat="server" 
        ShowFooter="True" onitemcommand="RadGrid1_ItemCommand" 
        ondeletecommand="RadGrid1_DeleteCommand" 
        oninsertcommand="RadGrid1_InsertCommand" 
        onupdatecommand="RadGrid1_UpdateCommand" >
    <MasterTableView DataKeyNames="Title" AutoGenerateColumns="false" EditMode="InPlace" CommandItemDisplay="TopAndBottom" CommandItemSettings-AddNewRecordText="Add New Item" >
                    <Columns>
                     <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"
                            ConfirmDialogWidth="220px">
                        </telerik:GridButtonColumn>
  
                     <telerik:GridTemplateColumn DataField="Title" HeaderText="Product Number" UniqueName="ProductNumber"
                            Visible="true">
                            <InsertItemTemplate>
                                <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text='<%# Bind("Title") %>' >
                                </telerik:RadTextBox>
                            </InsertItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text='<%# Eval("Title") %>' >
                                </telerik:RadTextBox>
                            </EditItemTemplate>    
                            <ItemTemplate>
                            <telerik:RadTextBox ID="RadtxtPrdNumber" ReadOnly="true" runat="server" Text='<%# Eval("Title") %>' />
                            </ItemTemplate>                       
                        </telerik:GridTemplateColumn>                     
                          
    </Columns>
    </MasterTableView>
     <ClientSettings EnableRowHoverStyle="true">
        </ClientSettings>
  
    </telerik:RadGrid>
</div>


How to fix this?
Thanks

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 06 Dec 2012, 11:58 AM
Hi,

 When you use RadAjaxManager in Sharepoint 2010 the ajax settings have to be created entirely in the code-behind of the web part as shown below:

RadAjaxManager ajaxmgr;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ajaxmgr = RadAjaxManager.GetCurrent(Page);
            if (ajaxmgr == null)
            {
                ajaxmgr = new RadAjaxManager();
                Page.Items.Add(typeof(RadAjaxManager), ajaxmgr);
            }
 
            if (Page.Form != null)
            {
                Page.Form.Controls.AddAt(0, ajaxmgr);
            }
            EnsureChildControls();
        }
 
        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
 
            RadAjaxLoadingPanel loadingPanel = control.FindControl("RadAjaxLoadingPanel1") as RadAjaxLoadingPanel;
            RadGrid grid = control.FindControl("RadGrid1") as RadGrid;
            //Find more controls to add to the ajax settings
            if (ajaxmgr != null)
            {
                ajaxmgr.AjaxSettings.AddAjaxSetting(grid, grid, loadingPanel);
            }
 
        }

Additional information can be found in this help topic:
http://www.telerik.com/help/aspnet-ajax/moss-create-ajax-enabled-sharepoint-webpart-radcontrols.html

All the best,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or