Radgrid not refreshing after ajax and rebind

44 posts, 0 answers
  1. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 29 May 2008 Link to this post

    Hi,

    I have a main page with a radgrid. Double clicking the grid opens up a radwindow that lets the users edit the grid row data. I want the grid on the parent page to refresh without having to do a full page refresh. I tried the Ajax call. Everything seem to work as expected. But the grid does not seem to refresh. I can debug the code and see that the server side code does fireup and the grid rebinds successfully. It just does not show up on screen. Here is my code.

    On the main page, I have the AJAX manager as below.

    <

    telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
    <UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="grdAdminList" />
    </UpdatedControls>
    </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManager>


    Here is the server side code:

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
    if (e.Argument == "Rebind")
    {
    grdAdminList.Rebind();
    }

    Here is the code that I have on my radwindow close:
    This function calls the actual refreshGrid function that is on the main page.

    function

    refreshGrid()
    {
    GetRadWindow().BrowserWindow.refreshGrid();
    }

    Main page function:
    function refreshGrid()
    {
    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
    }

    What  am I missing here?

    Thanks!
    vithiya

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 May 2008 Link to this post

    Hi,

    Go through the following help articles.

    Exclude controls from ajaxifying
    Forcing postback
    Frequently Asked Questions

    Shinu.
  3. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 30 May 2008 Link to this post

    Hi Shinu,

    Thank you for the quick response. But I am not sure how the links you provided are related to what I am trying to accomplish. I do not have an ajaxpanel in my app. I only have ajaxmanager. The code behind is working as expected and the ajax request is being processed as well. When I debug the code, I can see it stepping through the ajax request and rebinding the grind which then has the updated data. It's the grid on the screen that does not show the updated data. To me it looks like the client side is missing something. Please look at my code that I posted earlier and confirm that at least I am going in the right direction.

    Thanks!
    vithiya
  4. DeadlyAccurate
    DeadlyAccurate avatar
    5 posts
    Member since:
    Jan 2008

    Posted 30 May 2008 Link to this post

    I had to set EnableViewState="false" to get mine to refresh.
  5. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 30 May 2008 Link to this post

    That did it!

    Thanks a lot!
    vithiya
  6. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 30 May 2008 Link to this post

    I have a question about setting the EnableViewState property to false. We do use the viewstate property to store values throughout the application. By turning off  the property aren't we messing up our application? Or does it stay unaffected while using ajax? Can somebody from telerik confirm that this is an acceptable solution? If not please suggest other ways to get the ajax call to work without disbaling the viewstate property.

    Thanks!
    vithiya
  7. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 13 Jun 2008 Link to this post

    Ok, while there was no response for my previous question, here is another one.

    I am now trying to move the AjaxManager control to the master page and manage ajax calls on the content page using the AjaxManagerProxy control.

    After doing so, when I try to initiate the ajaxrequest call using javascript, it does not seem to find the ajaxmanager at all. Here is the code to make the ajaxrequest call.

    var

    radMgr = $find("<%= RadAjaxManagerMaster.ClientID %>");  (did not work)

    radMgr.ajaxRequest(

    "Rebind");

    Also tried,

    var radMgr = $find("<%= RadAjaxManagerProxy.ClientID %>");  (did not work)

    radMgr.ajaxRequest(

    "Rebind");

    And finally tried,

    var radMgr = $find("<%= RadAjaxManagerMaster.GetCurrent(Page).ClientID %>");  (did not work)

    radMgr.ajaxRequest(

    "Rebind");

    All of the above did not work. In the first and the last case, it kept saying that the control did not exist in the context. The second option did not give me any error message, but did not work either.

    Please let me know how I can get it to work.

    Thank you!
    vithiya

  8. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 16 Jun 2008 Link to this post

    Hi Vithiya,

    I think that the following online demo:

    http://www.telerik.com/DEMOS/ASPNET/Prometheus/Controls/Examples/Integration/GridAndWindow/DefaultCS.aspx?product=grid

    and the demo project from the relevant KB article on our site:

    http://www.telerik.com/support/kb/article/b454K-gmb-b454T-cba-b454c-cba.aspx

    can become the basis for your implementation. Additionally, how to reference the ajax manager in master/content page scenario and trigger ajax requests from the client you can learn from the resources pointed below:

    http://www.telerik.com/DEMOS/ASPNET/Prometheus/Ajax/Examples/Manager/MasterPage/DefaultCS.aspx
    http://www.telerik.com/help/aspnet-ajax/ajxmasterpageupdateeverywhere.html

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 16 Jun 2008 Link to this post

    Ok, after going through the articles that you pointed, I am still stuck at one point. I have made all suggested changes like moving hte ajax manager to the master page, creating an ajaxmanagerproxy in the content page and have added settings to the proxy. Now, when I tried to initiate the ajax request on the server side, it does not work.

    When I use the below code, I get a null exception (System.NullReferenceException: Object reference not set to an instance of an object.). I am trying to ajaxify a radgrid in the content page using the proxy.

    var

    radMgr = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");

    radMgr.ajaxRequest;

    Please advice!

    Thank you!
    vithiya

  10. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 17 Jun 2008 Link to this post

    Hello Vithiya,

    Does using a bit different syntax, namely:

    C#
    radMgr = $find("<%= RadAjaxManager.GetCurrent(this).ClientID %>");

    or 

    VB.NET
    radMgr = $find("<%= RadAjaxManager.GetCurrent(Me).ClientID %>");

    makes a difference? This is indeed an odd issue you come upon and the best means to progress in our investigation is to put together a working subset of your project and send it attached to a formal support ticket. We will examine it in detail and will advice you further.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Chris
    Chris avatar
    4 posts
    Member since:
    Oct 2008

    Posted 17 Oct 2008 Link to this post

    I am having a similar problem using the proxmanager to rebind a datagrid I get the following error


    The best overloaded method match for 'Telerik.Web.UI.RadAjaxManager.GetCurrent(System.Web.UI.Page)' has some invalid arguments


    I have a standard web page with the radscript manager and radajax manager.

    I have a user control based on the rad grid editing demo. instead of the ajax manager I am using the manager proxy in my user control

    this is the sample code i used to base my user control

    http://demos.telerik.com/aspnet/prometheus/Controls/Examples/Integration/GridAndWindow/DefaultCS.aspx?product=grid

    Any help will be appreciated

    Regards
    Chris
  12. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 20 Oct 2008 Link to this post

    Hi Chris,

    Try modifying the line in your code that throws the exception as below:

    Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page) 

    instead of trying to get manager instance as you did:

    Telerik.Web.UI.RadAjaxManager.GetCurrent(System.Web.UI.Page

    Let me know if this helps.

    Regards,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Phani
    Phani avatar
    3 posts
    Member since:
    May 2009

    Posted 11 May 2009 Link to this post

    Iam facing the same problem today. In my case it is working fine after i place the following code in RadAjaxManager1

    <telerik:AjaxSetting AjaxControlID="RadAjaxManagerModifyProtocol">

     

     

     

    <UpdatedControls>

     

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGridPIManager" />

     

     

     

    </UpdatedControls>

     

     

     

    </telerik:AjaxSetting>  

    and my complete code is below.

    Page1.aspx:

     

    <!-- Footer Section  -- In this footer user control i placed RadScriptManager which i used it in every page along
    with some footer text-->

     

     

    <tcn:footer ID="footer" runat="server" />

     

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">   
     <script type="text/javascript">   
     //<![CDATA[   
     function openRadWindow(protocol_id)   
     {  
         var oWnd = radopen("../popups/associateUser.aspx?id=" + user_id , "radwindow1")   
        oWnd.center();  
     }  
     
    function refreshGrid(arg)   
    {  
       if (arg = "Rebind"){   
          $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");   
       }      
    }  
     //]]>   
     </script>   
     </telerik:RadCodeBlock>  

     

     

     

    <telerik:RadWindowManager ShowContentDuringLoad="false" VisibleTitlebar="true" Modal="true" RestrictionZoneID="divMainBody" VisibleStatusbar="true" AutoSize="false" Skin="Black" ID="RadWindowManager1" Width="600px" Height="600px" runat="server">

     

    </telerik:RadWindowManager>

     

     

     

     

     

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" >   
     
     <AjaxSettings>   
         <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">   
                 <UpdatedControls>   
                       <telerik:AjaxUpdatedControl ControlID="RadGrid1" />   
                 </UpdatedControls>   
        </telerik:AjaxSetting>   
     
         <telerik:AjaxSetting AjaxControlID="RadGrid1">   
                 <UpdatedControls>   
                       <telerik:AjaxUpdatedControl ControlID="RadGrid1" />   
                 </UpdatedControls>   
         </telerik:AjaxSetting>   
     </AjaxSettings>
    </telerik:RadAjaxManager>

     

    Page1.aspx.vb (codebehind):

     

    Private Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
     
    //My own function with returns the dataset which assign   
    //to the RadGrid1.DataSource and No Databind() in this function.  
     
        UserManagerBindData()   
     
    End Sub 
     
     
    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As ObjectByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest   
              
            RadGrid1.MasterTableView.SortExpressions.Clear()  
            RadGrid1.MasterTableView.GroupByExpressions.Clear()  
            RadGrid1.Rebind()  
    End Sub   
     

     

     

    associateUser.aspx.vb (Popup-Codebehind):
    This popup contains a RadGrid2 with checkbox column and a Add User Button.
    In the button click event iam inserting the selected user record in the grid directly to the database.
    after succesffully inserted into database. I added the following code.

     

     

     

    Response.Write("<script language='javascript'>var oWindow = null; if (window.radWindow) oWindow = window.radWindow; else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; oWindow.close(); oWindow.BrowserWindow.refreshGrid('Rebind');</script>"

    Please note: Make sure the order of placing the RadManagers like The Script Manager followed by Ajax Manager as mentioned in the above code (Page1.aspx)

    Hope it helps some one like me..
    Thank you.

     

     

     

     

     

     

     

     

     

  14. Neo
    Neo avatar
    22 posts
    Member since:
    May 2005

    Posted 21 Sep 2010 Link to this post

    Setting EnableViewState="false" does the job for RadGrid rebind not updating data on the page content.
  15. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Dec 2010 Link to this post

    It does not seems to be your case but just in case someone has the same problem the I did...

    I did not know that I needed to authorize the events coming from the RadAjaxManager1to also update the grid. That did the trick for me and it seems logical.

    EnableViewState="false" should not be an option here to solve the problem...

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
  16. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 27 Jan 2011 Link to this post

    I've used all the code provided, but I still cannot get my radgrid to refresh.  My datasource is bound in my code behind. I did a watch on the binding, and the data is there like it's supposed to be, the grid is just not refreshing on the screen/page.

    I don't want to set enableviewstate="false" unless I have to.  Is there another way around this?  I am providing my code below.

    ASPX:
    <script type="text/javascript">
                   function onRequestStart(sender, args) {
                       if (args.get_eventTarget().indexOf("excelExport") >= 0) {
                           args.set_enableAjax(false);
                       }
                   }
                   function ShowInsertForm() {
                       var combo = $find("<%= RadComboBox1.ClientID %>");
                       var comboItem = combo.get_selectedItem();
                       if (!comboItem)
                       {
                           window.radopen("AddComment.aspx", "UserListDialog");
                       }
                       else {
                           window.radopen("AddComment.aspx?PO=" + comboItem.get_value("PO"), "UserListDialog");
                       }
                       return false;
                   }
                   function refreshGrid() {
                           $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                   }
               </script>
               <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server" Skin="WebBlue">
               </telerik:RadFormDecorator>
           <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
            <ClientEvents OnRequestStart="onRequestStart" />
           <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelHeight="100%"/>
                   </UpdatedControls>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="RadGrid1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelHeight="100%" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="RadFilter1">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadFilter1" />
                       </UpdatedControls>
               </telerik:AjaxSetting>
           </AjaxSettings>
       </telerik:RadAjaxManager>
           <asp:Table runat="server" ID="table1" Width="873px">
               <asp:TableHeaderRow CssClass="style1">
                   <asp:TableHeaderCell ColumnSpan="2">Grant Communications - Admin</asp:TableHeaderCell>
               </asp:TableHeaderRow>
               <asp:TableRow>
                   <asp:TableCell CssClass="style1">
                       <telerik:RadComboBox ID="RadComboBox1" Runat="server" Skin="WebBlue"
                           Width="373px" AutoPostBack="true" EnableLoadOnDemand="True"
                           OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" MaxHeight="350px"
                           Text="Select a Grant" EmptyMessage="Select a Grant">
                       </telerik:RadComboBox>
                   </asp:TableCell>
                   <asp:TableCell CssClass="style1">
                       <asp:Label runat="server" ID="lblResult"></asp:Label>
                   </asp:TableCell>
               </asp:TableRow>
               <asp:TableRow>
                   <asp:TableCell CssClass="style1" ColumnSpan="2">
                       <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
                           AllowPaging="True" AllowSorting="True" GridLines="None" Skin="WebBlue"
                           OnNeedDataSource="RadGrid1_NeedDataSource"
                           OnDataBound="RadGrid1_DataBound" width="873px"
                           AutoGenerateColumns="False">
                           <ExportSettings  ExportOnlyData="True" IgnorePaging="true" OpenInNewWindow="true">
                               <Excel Format="ExcelML" />
                           </ExportSettings>
                           <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                           </ClientSettings>
                           <MasterTableView CommandItemDisplay="Top" >
                               <CommandItemSettings >
                                </CommandItemSettings>
                               <RowIndicatorColumn>
                                   <HeaderStyle Width="20px"></HeaderStyle>
                               </RowIndicatorColumn>
                               <ExpandCollapseColumn>
                                   <HeaderStyle Width="20px"></HeaderStyle>
                               </ExpandCollapseColumn>
                               <Columns>
                                   <telerik:GridBoundColumn DataField="Muni_Name" HeaderText="Grantee"
                                       UniqueName="column">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn DataField="PO" HeaderText="PO" UniqueName="column1">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn DataField="CommentDate" FilterControlWidth="30px"
                                       HeaderText="Comment Date" UniqueName="column2">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn DataField="Commentor" HeaderText="Commentor"
                                       UniqueName="column3">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn DataField="Comment" HeaderText="Comment"
                                       UniqueName="column4">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn DataField="InsertDate" FilterControlWidth="30px"
                                       HeaderText="Insert Date" UniqueName="column5">
                                   </telerik:GridBoundColumn>
                               </Columns>
                               <CommandItemTemplate>
                                   <a href="#" onclick="return ShowInsertForm();">Add New Record</a>
                                   <asp:ImageButton ID="excelExport" runat="server" ImageUrl="~/images/ExportToExcel.gif" CommandName="ExportToExcel" />
                               </CommandItemTemplate>
                           </MasterTableView>
                       </telerik:RadGrid>
                   </asp:TableCell>
               </asp:TableRow>
           </asp:Table>
     
           <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" Skin="WebBlue">
                   <Windows>
                       <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Width="370px" Height="350px"
                           ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" />
                   </Windows>
           </telerik:RadWindowManager>

    VB:
       Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
           If e.Argument = "Rebind" Then
               RadGrid1.MasterTableView.SortExpressions.Clear()
               RadGrid1.MasterTableView.GroupByExpressions.Clear()
               RadGrid1.Rebind()
           End If
       End Sub
     
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
           connSql.ConnectionString = sqlConn.ToString()
           Dim poSqlCom As New SqlCommand("dbo.getRAComment", connSql)
           poSqlCom.CommandType = CommandType.StoredProcedure
           poSqlCom.Parameters.AddWithValue("@User", "Admin")
           poSqlCom.Parameters.AddWithValue("@PO", RadComboBox1.SelectedValue.ToString())
     
           Dim adapter As New SqlDataAdapter(poSqlCom)
           Dim links As New DataTable()
     
           Try
               adapter.Fill(links)
           Catch ex As Exception
               lblResult.Text = ex.Message
               If connSql.State = ConnectionState.Open Then
                   connSql.Close()
               End If
           End Try
     
           RadGrid1.DataSource = links
     
       End Sub
     
       Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.DataBound
           If connSql.State = ConnectionState.Open Then
               connSql.Close()
           End If
       End Sub 'RadGrid1_DataBound

    I appreciate any help on this that I can get!
  17. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 27 Jan 2011 Link to this post

    Your code looks fine to me... Just, could you clarify when you expect your grid to refresh?
    I guess that you expect the grid to refresh after you add a comment with your popup form and close it?
    Because I don't see what is calling the javascript refreshGrid method.

    this is probably obvious for you, but just in case, you have to close your popup like that:
    protected void btnClose_Click(object sender, EventArgs e)
    {
        //ScriptManager Enables AJAX In Your Web Apps
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CloseAndRebind();", true);
    }

    which will call the folowing popup javascript:
    <script type="text/javascript">
        //reload the parent
        function CloseAndRebind(args) {
            GetRadWindow().Close();
            GetRadWindow().BrowserWindow.refreshGrid(args);
        }
     
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow; //Will work in Moz in all cases, including classic dialog
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow; //IE (and Moz as well)
     
            return oWindow;
        }

    This is the part that will call the refreshgrid...

    and last maybe that you are using  Page.ClientScript.RegisterStartupScript instead of ScriptManager.RegisterStartupScript or vice versa...

    If you are already doing all this, please, post a 'working' sample so that somebody can check after you code...

    Kind regards,
    John.

  18. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 27 Jan 2011 Link to this post

    Hi, John.
     Yes.  I want the grid to refresh after I have added a new record.  When I put a break at the databind (after the record is added), I can see the added data in the radgrid.mastertablebview items. 

    I typed: ? radgrid1.MasterTableView.Items(2).Cells(6).Text into the immediate window (in Visual Studio), and got this result: "87456".
    ? radgrid1.MasterTableView.Items(2).Cells(4).Text
    "1/27/2011 12:00:00 AM"

    The grid is just not refreshing on the screen.  I don't know how else to explain it.

    I do have a addrecord.aspx page that has all the code you mentioned.  I did change from clientscript.registerstartupscript to scripmanager.registerstartupscript, but that didn't make a difference.

    Here's the code I have for that page:
    <form id="form1" runat="server">
               <script type="text/javascript">
                   function CloseAndRebind() {
                       GetRadWindow().BrowserWindow.refreshGrid();
                       GetRadWindow().close();
                   }
     
                   function GetRadWindow() {
                       var oWindow = null;
                       if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                       else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
     
                       return oWindow;
                   }
     
                   function CancelEdit() {
                       GetRadWindow().close();
                   }
           </script>
       <div id="art-page-background-gradient">
           <asp:Table ID="Table1" runat="server" Height="200px">
               <asp:TableRow ID="tr1">
                   <asp:TableCell ColumnSpan="2">
                       <asp:Label ID="lblNone" runat="server"></asp:Label>
                   </asp:TableCell>
               </asp:TableRow>
               <asp:TableRow ID="tr2">
                   <asp:TableCell>
                       <asp:Label ID="Label1" runat="server" Text="Comment Date"></asp:Label>
                   </asp:TableCell>
                   <asp:TableCell>
                       <telerik:RadDatePicker ID="cmDate" Runat="server" DateInput-EmptyMessage="Select a Date" Skin="WebBlue" >
                       </telerik:RadDatePicker>
                       <asp:RequiredFieldValidator ID="PickerRequiredFieldValidator" runat="server" Display="Dynamic"
                       ControlToValidate="cmDate" ErrorMessage="Please select a date" ForeColor="Black" Font-Bold="True" Font-Italic="True" />
                   </asp:TableCell>
               </asp:TableRow>
               <asp:TableRow ID="tr3">
                   <asp:TableCell>
                       <asp:Label ID="Label2" runat="server" Text="Comment"></asp:Label><br />
                       <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                       ControlToValidate="txtComment" ErrorMessage="Must Enter Comment" ForeColor="Black" Font-Bold="True" Font-Italic="True" />
                   </asp:TableCell>
                   <asp:TableCell>
                       <telerik:RadTextBox ID="txtComment" TextMode="MultiLine" Runat="server" EmptyMessage="Type your comment" Rows="5">
                       </telerik:RadTextBox>                  
                   </asp:TableCell>
               </asp:TableRow>
               <asp:TableRow ID="tr4">
                   <asp:TableCell ColumnSpan="2">
                       <asp:Button ID="Button1" runat="server" Text="Add Comment" />
                          
                       <asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="false" />
                   </asp:TableCell>
               </asp:TableRow>
           </asp:Table>
     
        
           <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server"
               Skin="WebBlue" />
         <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
       </telerik:RadScriptManager>
     
       </div>
       </form>
    'VB
    Protected
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           'Sets up page
           Me.Page.Title = "Add Comment"
           If (Not Page.IsPostBack) Then
               cmDate.SelectedDate = DateTime.Today
           End If
       End Sub
     
       Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
           'Finishes setting up page.  If the PO is not pushed through, then an error message will appear on the page.  If PO exists, then the PO will appear on the page.
           If Request.QueryString("PO") Is Nothing Then
               lblNone.Text = "No PO Select.  Please select a PO in then click on the add new record."
               tr2.Visible = False
               tr3.Visible = False
               Button1.Visible = False
               Button2.Text = "Ok"
           Else
               lblNone.Text = Request.QueryString("PO")
           End If
       End Sub
     
       Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
           Try
               'Adds Comment to table
               connSql.ConnectionString = sqlConn.ToString()
               Dim exSqlCom As New SqlCommand("dbo.AddComment", connSql)
               exSqlCom.CommandType = CommandType.StoredProcedure
               exSqlCom.Parameters.AddWithValue("@PO", lblNone.Text)
               exSqlCom.Parameters.AddWithValue("@Commentor", "GP")
               exSqlCom.Parameters.AddWithValue("@CommentDate", cmDate.SelectedDate)
               exSqlCom.Parameters.AddWithValue("@Comment", txtComment.Text)
               exSqlCom.Parameters.Add("@ReturnValue", SqlDbType.Int)
               exSqlCom.Parameters("@ReturnValue").Direction = ParameterDirection.Output
     
               connSql.Open()
               exSqlCom.ExecuteNonQuery()
               connSql.Close()
     
               'Calls for grid rebind and closes this page.
               ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CloseAndRebind();", True)
           Catch ex As Exception
               lblNone.Text = ex.Message
               If connSql.State = ConnectionState.Open Then
                   connSql.Close()
               End If
           End Try
       End Sub
     
       Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
           'Closes the page, and cancels the update.
           ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CancelEdit();", True)
           'ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", True)
       End Sub
  19. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 27 Jan 2011 Link to this post

    No no, I understand...

    The ScriptManager.RegisterStartupScript thing did the trick for me. My problem was that the ajax event on the page was not triggered.

    Can you confirm that your code goes trough the RadAjaxManager1_AjaxRequest after you close the page and that the rebind is called?

    After that I would try to get your grid out of the table structure you have here just to make sure it does not interfere.

    Also does the grid refresh after you click on a refresh command button you could add on the grid?

    Does the grid refresh after you trigger a new postback on the grid page?

    It looks like everything works fine just the grid does not seem to understand it should load the data it gets back.

    Then last I would try to remove the ajaxmanager from the page to see if things are working when not ajaxified?

    Can't you put a small project together and hand it over so I can try it on my side?
  20. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2011 Link to this post

    John,
    Thanks for all your great questions.  It really pointed me into the right directions.  I tried pulling the grid out of the table, but that didn't seem to work.  Then I wondered, is it because it's on a masterpage?  I created a new page without a master, and copied all my controls and code to the new page.  Worked like a charm.

    I guess I have to do the ajax manager/ajax proxy thing.  I was hoping to avoid that because  I only need the ajaxmanager for the page itself.  No other content areas need the ajax manager.

    I'll let you know what gets the code to work.

    Thank you again for the guidance!

    GP
  21. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2011 Link to this post

    John, thanks again for all the help.

    Ok, so I got it to work.  It did have something to do with master/content pages.  The problem is, I have two content areas that both use the telerik script manager.  I had to put that out on the Master page to prevent errors.  The AjaxManager was hiccuping because it couldn't find that script manager.  I had to put the AjaxManager on the MasterPage, and put a ajaxmanagerproxy to the content page.

    My new issue is that my stylesheet is dropping for some reason.  I'll get that working.  However, that is not as relevant to this part of the discussion.  Here's the code to make the master/content ajaxmanager happy:

    MasterPage.aspx - just make sure your AjaxManager is loaded before the content, or else you will throw a null exception when the content script tries to find the Master's AjaxManager
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" />


    CommentReport.aspx
    <asp:Content ID="Content5" ContentPlaceHolderID="SheetContentPlaceHolder" runat="server">
    <telerik:RadCodeBlock ID="rcb1" runat="server">
        <script type="text/javascript">
            function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("excelExport") >= 0) {
                    args.set_enableAjax(false);
                }
            }
            function ShowInsertForm() {
                var combo = $find("<%= RadComboBox1.ClientID %>");
                var comboItem = combo.get_selectedItem();
                if (!comboItem) {
                    window.radopen("AddComment.aspx", "UserListDialog");
                }
                else {
                    window.radopen("AddComment.aspx?PO=" + comboItem.get_value("PO"), "UserListDialog");
                }
                return false;
            }
            function refreshGrid() {
                $find("<%= RadAjaxManager.GetCurrent(me).ClientID %>").ajaxRequest("Rebind");
            }
        </script
    </telerik:RadCodeBlock>
        <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server" Skin="WebBlue">
        </telerik:RadFormDecorator>
            <telerik:RadAjaxManagerProxy ID="RAMP1" runat="server" >
            <AjaxSettings>
                 <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManagerProxy>
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
                            AllowPaging="True" AllowSorting="True" GridLines="None" Skin="WebBlue"
                            OnNeedDataSource="RadGrid1_NeedDataSource"
                            OnDataBound="RadGrid1_DataBound" width="873px"
                            AutoGenerateColumns="False">
                            <ExportSettings  ExportOnlyData="True" IgnorePaging="true" OpenInNewWindow="true">
                                <Excel Format="ExcelML" />
                            </ExportSettings>
                            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                            </ClientSettings>
                            <MasterTableView CommandItemDisplay="Top" >
                                <CommandItemSettings >
                                 </CommandItemSettings>
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn>
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridBoundColumn DataField="Muni_Name" HeaderText="Grantee"
                                        UniqueName="column">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="PO" HeaderText="PO" UniqueName="column1">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="CommentDate" FilterControlWidth="30px"
                                        HeaderText="Comment Date" UniqueName="column2">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Commentor" HeaderText="Commentor"
                                        UniqueName="column3">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Comment" HeaderText="Comment"
                                        UniqueName="column4">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="InsertDate" FilterControlWidth="30px"
                                        HeaderText="Insert Date" UniqueName="column5">
                                    </telerik:GridBoundColumn>
                                </Columns>
                                <CommandItemTemplate>
                                    <a href="#" onclick="return ShowInsertForm();">Add New Record</a>
                                    <asp:ImageButton ID="excelExport" runat="server" ImageUrl="~/images/ExportToExcel.gif" CommandName="ExportToExcel" ImageAlign="Right" AlternateText="Export To Excel" />
                                </CommandItemTemplate>
                            </MasterTableView>
                        </telerik:RadGrid>
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" Skin="WebBlue">
           <Windows>
             <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Width="370px" Height="350px"ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" />
                    </Windows>
            </telerik:RadWindowManager>
    </asp:Content>

    CommentReport.aspx  - Just the part that will help with the example:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindToDataTable(RadComboBox1)
        End If
     
        Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Page)
        manager.ClientEvents.OnRequestStart = "onRequestStart"
        AddHandler manager.AjaxRequest, AddressOf manager_AjaxRequest
    End Sub
    'Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs)
    '    If e.Argument = "Rebind" Then
    '        RadGrid1.MasterTableView.SortExpressions.Clear()
    '        RadGrid1.MasterTableView.GroupByExpressions.Clear()
    '        RadGrid1.Rebind()
    '    End If
     
    'End Sub
    Protected Sub manager_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs)
        'handle the manager AjaxRequest event here
        If e.Argument = "Rebind" Then
            RadGrid1.MasterTableView.SortExpressions.Clear()
            RadGrid1.MasterTableView.GroupByExpressions.Clear()
            RadGrid1.Rebind()
        End If
    End Sub

    AddComment.aspx (Window Page)  Just the parts relevant to discussion
    <form id="form1" runat="server">
                <script type="text/javascript">
                    function CloseAndRebind() {
                        GetRadWindow().BrowserWindow.refreshGrid();
                        GetRadWindow().close();
                    }
     
                    function GetRadWindow() {
                        var oWindow = null;
                        if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
     
                        return oWindow;
                    }
     
                    function CancelEdit() {
                        GetRadWindow().close();
                    }
            </script>

    AddComment.vb (Just relevant parts)
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CloseAndRebind();", True)
     
    'or if you want to cancel the insert
     
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CancelEdit();", True)
  22. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 28 Jan 2011 Link to this post

    Very good news. Good work.

    Just to say, I also have a master page but do not use the proxy thing and it is working just fine.
    I did paste you code directly extracted from my working project.

    Anywa, at least by using the proxy manager you get javascript intelissense which I don't get without...

    Good luck with your project GP,
    John.
  23. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2011 Link to this post

    Is your RadScriptManager on your content page or on your master page?  If it's on the content page, that's probably why your ajaxmanager is working on the content page.  If not, I can't explain why it works for one and not the other.

    Anyway, Thank you again for your help.

    Have a great weekend!

    GP
  24. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 28 Jan 2011 Link to this post

    Thanks but I did nothing. I had the time to check some options with you.
    Sometimes I got into trouble and I'm happy to find someone just listening to my problems...

    So, no, the (rad)scriptmanager is in the main page.
    Here is how my controls are laid out.

    The master page:
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Proxi.SiteMaster" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
        <link href="~/Styles/qsf.css?t=<%= DateTime.Now.Ticks %>" rel="stylesheet" type="text/css" />
        <link href="~/Styles/Site.css?t=<%= DateTime.Now.Ticks %>" rel="stylesheet" type="text/css" />
        <link href="~/Styles/Styles.css?t=<%= DateTime.Now.Ticks %>" rel="stylesheet" type="text/css" />
        <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" />
        <style type="text/css">
             
        </style>
    </head>
    <body class="BODY">
        <form id="mainForm" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackErrorMessage="Une erreur est survenue.">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Windows7" />
        <script type="text/javascript">
        </script>
                            <asp:ContentPlaceHolder ID="HeadContent" runat="server">
                            </asp:ContentPlaceHolder>
                                <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        </form>
    </body>
    </html>


    The page:
    <%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Sessions.aspx.cs"    Inherits="Proxi.Sessions" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                //open child window to edit new record
    //the JS...
     
                //refresh current session grid
                function refreshGrid(arg) {
                    if (!arg) {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                    }
                    else {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                    }
                }
     
                });
            </script>
        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager ID="RadAjaxManager1" OnAjaxRequestError="AjaxRequestErrorHandler"
            runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
            Height="500px" AllowPaging="True" AllowSorting="True" PageSize="20" OnDeleteCommand="RadGrid1_DeleteCommand"
            OnUnload="RadGrid1_Unload" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
            OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand" GridLines="None"
            Culture="fr" OnPreRender="RadGrid1_PreRender">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage" DataKeyNames="SessionID"
    etc...

    The popup looks like yours... I emoved the js code. It's the same then yours...

    Spot any difference?

    John.
  25. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2011 Link to this post

    I see one major difference.  Instead of having a client events tag with an on request start, you have OnAjaxRequest="RadAjaxManager1_AjaxRequest" in your main tag.

    I switched to that, and it seems to work, but the grid sort of "blinks" for a second.  It disappears and reappears.  When I use the proxy, the grid updates without a blink, and then area behind it blinks as if it's reloading other bits.
  26. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2011 Link to this post

    I'm such a dummy.  My onRequestStart in the Javascript was disabling AJAX or setting it to nothing.  I added an else clause that set the enableAJAX to true.  I put my table back in, and dropped the loading panel, grid, etc in there.  No more blinkies, and it works correctly.

    Regardless, folks, you now have a bunch of ways to reach the same goal.

    Whew...
  27. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 28 Jan 2011 Link to this post

    Good to know that there was a reason for your 'problem' actually ;)
    You'll have a better weekend now, hopefully :)
  28. ravi
    ravi avatar
    4 posts
    Member since:
    Mar 2011

    Posted 21 Mar 2011 Link to this post

     

    Hello Telerik ,
    i have problem with radajaxmanager,i have 2 radgrids in my page,while i am clicking the first radgrid itemcommand event ,i need to bind second radgrid ,i am using radajaxmanager,because of this i am unable to bind data to the second radgrid.when i removed radajaxmanager i am able to bind,but i need that radajaxmanager to open radwindow.i did my binding to first radgrid with the example of "http://demos.telerik.com/aspnet-ajax/controls/examples/integration/grwindow/defauidandltcs.aspx?product=window".please give me some idea.
  29. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 21 Mar 2011 Link to this post

    Can you post your radajaxmanager code from your asp?  It should look like this:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents OnRequestStart="onRequestStart" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"  />
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            </AjaxSettings>
    </telerik:RadAjaxManager>
  30. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 21 Mar 2011 Link to this post

    ravi, see also how master/detail grid relation is defined with ajax manager on this example:
    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx

    Also bear in mind that window editing is supported directly with popup edit form:
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/popupeditform/defaultcs.aspx

    Kiara
Back to Top