Dynamic URL and refresh grid

8 posts, 0 answers
  1. Jim
    Jim avatar
    6 posts
    Member since:
    Apr 2011

    Posted 03 Oct 2011 Link to this post

    My problem is similar to those of others with a twist. I need to refresh the original grid (ASP) that called the radwindow.

    I call the window somewhat differently.
     
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
           {
               int index = Convert.ToInt32(e.CommandArgument);
               String value1 = GridView1.Rows[index].Cells[0].Text;
               String value2 = GridView1.Rows[index].Cells[21].Text;
               Stat.Text = GridView1.Rows[index].Cells[15].Text;
               JRID.Text = value1;
               if (e.CommandName == "Lead")
               {
                   Emp.Text = GridView1.Rows[index].Cells[22].Text;
                   //GridView4.DataBind();
                   //SetFocus("Empview");
                   Label4.Text = "~/EmpLog2d.aspx?rdate=" + DropDownList1.SelectedValue + "&emp=" + Emp.Text;
                   this.RadWindow1.NavigateUrl = Label4.Text;
                   RadWindow1.VisibleOnPageLoad = true; }               
     

    The window is a information and verification page that runs several stored procedures then the user will close it.

    But on close I need to run  Gridview1.DataBind();

    and java is a foreign language to me.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Oct 2011 Link to this post

    Hello Jim,

    One approach is to add RadAjaxManager on page so that you can call the AjaxRequest from "OnClientClose" event of RadWindow. Then it is possible to rebind the RadGrid from server side, inside the "RadAjaxManager1_AjaxRequest" method. Here is the sample code snippet to achieve this.

    C#:
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
       <Windows
         <telerik:RadWindow runat="server" OnClientClose="closeRadWindow" Behavior="Default" InitialBehavior="None"  
              Left="" NavigateUrl="window.aspx" OpenerElementID="Button1"  
               style="display:none;" Top=""
         </telerik:RadWindow
      </Windows
    </telerik:RadWindowManager
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  
          onajaxrequest="RadAjaxManager1_AjaxRequest"
         <AjaxSettings
              <telerik:AjaxSetting AjaxControlID="RadGrid1"
                  <UpdatedControls
                      <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                  </UpdatedControls
              </telerik:AjaxSetting
              <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                  <UpdatedControls
                      <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                  </UpdatedControls
              </telerik:AjaxSetting
         </AjaxSettings
    </telerik:RadAjaxManager

    Javascipt:
    <script type="text/javascript"
    function closeRadWindow() 
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();  
    </script>

    C#:
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
      RadGrid1.MasterTableView.SortExpressions.Clear(); 
      RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
      RadGrid1.Rebind(); 
    }

    Another approach is to hook OnClientClose to the RadWindow and rebind the grid.
    Client side:
    function OnClientClose()
    {
      var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
      masterTable.rebind();
    }

    Thanks,
    Shinu.
  3. Jim
    Jim avatar
    6 posts
    Member since:
    Apr 2011

    Posted 04 Oct 2011 Link to this post

    Thanks for your reply Shinu

    After a few syntax corrections I was able to get your example to run without errors.
     
    However Gridview1 is no longer Visible on page load.

            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" 
                Animation="Resize" AutoSize="True" InitialBehaviors="Resize" 
                KeepInScreenBounds="True" MinHeight="150px" MinWidth="680px" 
                VisibleStatusbar="False" VisibleTitlebar="False" 
                >
              <Windows>
               <telerik:RadWindow ID="RadWindow1" runat="server" AutoSize="True" 
               OnClientClose="closeRadWindow"
                KeepInScreenBounds="True" 
                NavigateUrl="~/EmpLog2d.aspx">
            </telerik:RadWindow>
              </Windows>
            </telerik:RadWindowManager>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="GridView1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="GridView1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="GridView1" />
                </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
      
             <br />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="MachineRunID" DataSourceID="SqlDataSource1" CellPadding="2" 
                onrowdatabound="GridView1_RowDataBound" 
                onrowcommand="GridView1_RowCommand" style="margin-top: 0px">
                <Columns>
    ........

    <body>
        <script type="text/javascript">
            function closeRadWindow()
            {
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
            }  
    </script>
        <form id="form1" runat="server">

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
     {
         GridView1.DataBind();
     }

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4616 posts

    Posted 05 Oct 2011 Link to this post

    Hello Jim,

    I'll start off by pointing out that Resize is not a supported option for the InitialBehaviors property. The available options are explained in this help article: http://www.telerik.com/help/aspnet-ajax/window-behavior-initial-window-state.html.

    As for the GridView not being visible - I cannot find a reason for this in your code, so I would advise that you examine your CSS rules for display changes regarding table elements. Please also make sure that your datasource returns data so that the grid has something to show in the first place. Is this behavior observed only when the RadAjaxManager is used or without it as well? Can you reproduce it with a simple Update Panel? If so then the issue stems from something else in your logic that is not related to the RadControls.

    You can also try wrapping the GridView in a regular asp UpdatePanel and placing a hidden button in its ContentTemplate as well, then you can get it via JavaScript and call its click() method to perform the AJAX request, then rebind the grid in the button's Click event (for example $get("<%=ButtonRebind.ClientID %>").click(); in the OnClientClose event of the RadWindow where ButtonRebind is the ID of the said button).

    I would also advise that you examine the following online demo which is very similar to your scenario, but uses a RadGrid: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window.




    Kind regards,
    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
  5. Jim
    Jim avatar
    6 posts
    Member since:
    Apr 2011

    Posted 05 Oct 2011 Link to this post

    The gridview not showing is because of 

     

    <

     

     

    telerik:AjaxUpdatedControl ControlID="GridView1" />

     


    If it is removed the grid shows.  but then the databind does not fire

    also the RadAjaxManager Is throwing errors in the radscript manager and the radwindow manager

    Error Rendering Control - RadScriptManager1An unhandled exception has occurred.

    [A]Telerik.Web.UI.RadScriptManager cannot be cast to [B]Telerik.Web.UI.RadScriptManager. Type A originates from 'Telerik.Web.UI, Version=2011.2.915.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' in the context 'LoadNeither' at location 'C:\Users\System Design\AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies\u9arrfu_01\telerik.web.ui.dll'. Type B originates from 'Telerik.Web.UI, Version=2011.2.915.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' in the context 'LoadNeither' at location 'C:\Users\System Design\AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies\e-irpyg-01\Telerik.Web.UI.dll'.



    RadWindowManager - RadWindowManager1There was an error rendering the control.

    Check to make sure all properties are valid.


  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4616 posts

    Posted 07 Oct 2011 Link to this post

    Hello Jim,

    On the error thrown by the designer I advise that you examine the following help article: http://www.telerik.com/help/aspnet-ajax/introduction-design-time-troubleshooting.html and more precisely its last seciont which describes the exact error message you are having.

    On the matter of the grid that is not rendered - I advise that you start building your project on top of the demo I previously linked. You can find it in the LiveDemos folder in your RadControls installation. Once you open the solution you can examine and modify the code freely. Once you achieve the desired functionality you can incorporate it in your actual project. I also advise that you check for the presence of the AjaxControlToolkit assembly - if it is in the Bin folder some of the MS AJAX scripts get referenced from it and these versions are somehow modified and do not work properly. You can also try the approach with the hidden button and the regular update panel.


    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
  7. Jim
    Jim avatar
    6 posts
    Member since:
    Apr 2011

    Posted 07 Oct 2011 Link to this post

    Thanks for the reply Marin

    This PC has never had the trial version installed and it runs visual studio 2010 on windows7 64bit.

    There are no Ajax links in the bin folder (see attached)
     

    I am looking to add radwindow to a bunch of solutions already existing with some very complex Gridviews.
     So reworking them in radgrid is not a attractive option.
  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4616 posts

    Posted 10 Oct 2011 Link to this post

    Hi Jim,

    On the design time error please examine this forum thread. It is related to an older version of the RadControls for ASP.NET AJAX, yet if you have had it installed while working with this project this may still be applicable.

    This design time error is caused by having two instances of the Telerik.Web.UI assembly having different versions, loaded in the same Visual Studio AppDomain.

    Besides the problem, described in the article, this could happen as a result of a reference update, e.g: a page with RadControls was loaded in design mode, the reference was updated and the page got reloaded again. This is a one-time only problem and its fix involves a Visual Studio restart.

    Another possible reason for that is that the solution contains multiple projects, each referencing a different RadControls for ASP.NET AJAX assembly. Thus, loading a page with a RadControl from ProjectA in design mode and loading a page with a RadControl from ProjectB could result in the TypeCastException.

    In that case I would suggest that you either update both the projects to use the same RadControls assembly, or split the projects to different solutions. Please, restart Visual Studio after any of the approaches.



    On the matter with the GridView - please make sure if the GridView renders at all in the page. You can do so by examining the rendered HTML with a tool like firebug or the IE Dev Toolbar. It is possible that some of the containers have specific height set or have their height set as 100% and are, therefore invisible because of some inherited size properties. You can confirm this via the UpdatePanelHeight property of the AjaxUpdatedControl inner tag. Try setting it to 100% or to some hard value in pixels. If this starts showing the GridView please examine the DOM tree for missing sizes and set them accordingly.


    What I meant for the Demos was that you can start off with this runnable page and replace the RadGrid with your GridView (of course, the code-behind needs to be altered a bit to accommodate the different events from the GridView that will add the client-side handler, which opens the RadWindow). Once this project runs as expected the same settings should be applicable for your original project as well.


    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
Back to Top