PostBack using RadAjaxManager

2 posts, 0 answers
  1. VnDevil
    VnDevil avatar
    58 posts
    Member since:
    Oct 2012

    Posted 19 Jun 2010 Link to this post

    Hi,

    I want to PostBack RadGrid with RadAjaxManager when close RadWindow, but ajaxRequestWithTarget doesn't work in my code below, please help me fix this

    ASPX Page
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head id="Head1" runat="server"
        <title>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
        </telerik:RadWindowManager> 
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
            <script language="javascript" type="text/javascript"
                function openConfirmDeleteMany() { 
                    var oWnd = radopen("ConfirmDeleteMany.aspx", "ConfirmDeleteManyWindow"); 
                    oWnd.SetSize(400, 200); 
                    oWnd.SetTitle('Title'); 
                    oWnd.Center(); 
                } 
     
                function OnDeleteWindowClientClose(oWnd, args) { 
                    if (args) { 
                        var hdfDeleteOption = document.getElementById("<%= hdfDeleteOption.ClientID %>"); 
                        hdfDeleteOption.value = args
                        var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>"); 
                        ajaxManager.ajaxRequestWithTarget('<%= RadGrid1.UniqueID %>', ''); 
                    } 
                } 
            </script> 
     
        </telerik:RadCodeBlock> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadGrid1"
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <asp:HiddenField ID="hdfDeleteOption" runat="server" /> 
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1" GridLines="None" 
            AllowPaging="true" PageSize="20" AllowSorting="true" Skin="Vista" AllowFilteringByColumn="true" 
            OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand"
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="AccessDataSource1"
                <Columns> 
                    <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID" 
                        ReadOnly="True" SortExpression="EmployeeID" UniqueName="EmployeeID"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName" 
                        UniqueName="LastName"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" 
                        UniqueName="FirstName"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" SortExpression="Title" 
                        UniqueName="Title"
                    </telerik:GridBoundColumn> 
                    <telerik:GridTemplateColumn> 
                        <ItemTemplate> 
                            <asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="cmdDelete" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
        <asp:AccessDataSource ID="AccessDataSource1" DataFile="~/App_Data/Nwind.mdb" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees]" 
            runat="server"></asp:AccessDataSource> 
        </form> 
    </body> 
    </html> 

    Code-behind:
            protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
            { 
                if (e.Item is GridDataItem) 
                { 
                    var item = e.Item as GridDataItem; 
                    var btnDelete = (LinkButton)item.FindControl("btnDelete"); 
                    btnDelete.OnClientClick = "openConfirmDeleteMany(); return false;"
                } 
            } 
     
            protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
            { 
                if(e.CommandName == "cmdDelete"
                { 
                    Response.Write(RadGrid1.MasterTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"]); 
                } 
            } 


    ConfirmDeleteMany.aspx
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head id="Head1" runat="server"
        <link href="/App_Themes/Administrator/adminStyle.css" rel="stylesheet" /> 
        <script src="/Scripts/Portal.js"type="text/javascript" language="javascript"></script> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     
        <script language="javascript" type="text/javascript"
     
            function GetRadWindow() { 
                var oWindow = null
                if (window.radWindow) oWindow = window.radWindow; 
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
                return oWindow; 
            } 
             
            function returnToParent() { 
     
                if (confirm('Are you sure?')) { 
                    var comboBox = $find("<%= ddlDeleteOption.ClientID %>"); 
                    var item = comboBox.get_selectedItem(); 
                    //alert(item.get_value()); 
                    //get a reference to the current RadWindow 
                    var oWndRad = GetRadWindow(); 
     
                    var openerPage = oWndRad.BrowserWindow; 
                    openerPage.OnDeleteWindowClientClose(oWndRad, item.get_value()); 
                    oWndRad.close(); 
                } 
            } 
        </script> 
     
        <table cellpadding="2" cellspacing="2" border="0" width="100%"
            <tr> 
                <td> 
                    <telerik:RadComboBox ID="ddlDeleteOption" runat="server"
                        <Items> 
                            <telerik:RadComboBoxItem Text="Delete One" Value="ONE" /> 
                            <telerik:RadComboBoxItem Text="Delete All" Value="ALL" /> 
                        </Items> 
                    </telerik:RadComboBox> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClientClick="returnToParent(); return false;" /> 
                </td> 
            </tr> 
        </table> 
        </form> 
    </body> 
    </html> 



  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 21 Jun 2010 Link to this post

    Hello,

    Try to change your AjaxSettings as shown below and see if it makes a difference.
    ASPX:
    <telerik:RadAjaxManager id="RadAjaxManager1" runat="server">
      <AjaxSettings>
         <telerik:AjaxSettings AjaxControlID="RadGrid1" >
            <UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
         </telerik:AjaxSettings>
       </AjaxSettings>
    </telerik:RadAjaxManager>

    For more information, please refer to these articles:
    http://www.telerik.com/help/aspnet-ajax/ajxclientsideapi.html
    http://demos.telerik.com/aspnet-ajax/ajax/examples/manager/clientsideapi/defaultcs.aspx

    Regards,
    Pavlina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top