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

Rebind of RadGrid Reopens up a RadWindow with RadContextMenu

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pat Huesers
Top achievements
Rank 1
Pat Huesers asked on 07 Jan 2014, 08:17 PM

I have a page that has a RadGrid with a Context Menu on it.   I am using the context menu to fire open a RadWindow that is hosting another aspx page with a RadProgressArea completing a long running process.   Once the job is finished I have some JS in a placeholder that I make visable to Rebind the radgrid and then close the RadWindow.


Everything works fine except if I rebind the RadGrid the RadWindow reopens back up.   What am I doing wrong?



Here is the main aspx page - stripped down to be simple.



<%@ Control Language="VB" AutoEventWireup="false" CodeFile="PartInventory.ascx.vb" Inherits="UserControls_PartInventory" %>
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock2">
 
        <script type="text/javascript">
            
            function RowContextMenu(sender, eventArgs) {
                  
                var menu = $find("<%=RadMenu1.ClientID %>");
                var evt = eventArgs.get_domEvent();
 
                if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
                    return;
                }
                var index = eventArgs.get_itemIndexHierarchical();
                document.getElementById("radGridClickedRowIndex").value = index;
 
                sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
                menu.show(evt);
                evt.cancelBubble = true;
                evt.returnValue = false;
 
                if (evt.stopPropagation) {
                    evt.stopPropagation();
                    evt.preventDefault();
                 
                }
            }
 
            function refreshGrid() {
                var masterTable = $find("<%=rgInventoryEdit.ClientID%>").get_masterTableView();
                masterTable.rebind();
            }
 
 
        </script>
 
    </telerik:RadCodeBlock>
<telerik:RadGrid ID="rgInventoryEdit" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" DataSourceID="sqlInventory" GridLines="None" Skin="WebBlue"
     AllowMultiRowSelection="true"  AllowAutomaticDeletes="True" >
    <ClientSettings>
            <ClientEvents OnRowContextMenu="RowContextMenu" />
            <Selecting CellSelectionMode="None" AllowRowSelect="True"></Selecting>
            <Resizing AllowColumnResize="True" AllowResizeToFit="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True"></Resizing>
        </ClientSettings>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="InventoryID" DataSourceID="sqlInventory"  PageSize="25" ShowFooter="True" ShowHeader="true"  CommandItemDisplay="Top">
         <CommandItemTemplate>
                <div style="padding: 5px 5px;">
                      <asp:LinkButton ID="LinkButton1" runat="server" OnClick="SaveGridSettings" CommandName="SaveSettings"><img style="border:0px;vertical-align:middle;"  alt="" src="../../Images/Icons/24x24/save24x24.png"/> Save Layout</asp:LinkButton>   
                </div>
            </CommandItemTemplate>
        <Columns>
            <telerik:GridTemplateColumn HeaderText="Img"  AllowFiltering="False"  UniqueName="HasImages">
                <HeaderStyle Width="35px"></HeaderStyle>
                <ItemStyle Width="35px"></ItemStyle>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" Text="Link" Target="_blank" Visible='<%# Eval("HasImages")%>' ImageUrl="~/Images/BlueIcons/16x16/blue16_032.gif" onclick="window.open (this.href, 'child', 'height=800,width=800,scrollbars'); return false"
                        NavigateUrl='<%# String.Format("~/CarAndPartPics.aspx?NoMaster=True&InventoryNumber={0}&StockNumber={1}", Convert.ToString(Eval("InventoryNumber")), Convert.ToString(Eval("StockTicketNumber")))%>' />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>
            
             <telerik:GridButtonColumn ConfirmText="Delete this Part?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                    UniqueName="DeleteColumn">
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<telerik:RadPersistenceManagerProxy ID="RadPersistenceManagerProxy1" runat="server">
        <PersistenceSettings>
            <telerik:PersistenceSetting ControlID="rgInventoryEdit" />
        </PersistenceSettings>
</telerik:RadPersistenceManagerProxy>
<input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" />
<telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" SkinID="WebBlue"
        EnableRoundedCorners="true" EnableShadows="true">
        <Items>
            <telerik:RadMenuItem Text="Increase Prices">
            </telerik:RadMenuItem>
            <telerik:RadMenuItem Text="Do Multiple Operations">
            </telerik:RadMenuItem>
 
        </Items>
 
    </telerik:RadContextMenu>
<telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" runat="server" EnableShadow="true">
    <Windows>
        <telerik:RadWindow ID="rwOne" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" Behaviors="Close,Move"
                Modal="true" >
            </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>
<asp:SqlDataSource ID="sqlInventory" runat="server" ConnectionString="<%$ ConnectionStrings: %>"
   
</asp:SqlDataSource>




Here is the code Behind.

Imports Telerik.Web.UI
 
 
Partial Class UserControls_PartInventory
    Inherits System.Web.UI.UserControl
 
    Protected Sub UserControls_PartInventory_Load(sender As Object, e As EventArgs) Handles Me.Load
 
        If Not IsPostBack Then
            LoadTelerikPF()
        End If
    End Sub
 
    
 
    Public Function SaveTelerikPF() As Boolean
        Try
            Dim mstr As MasterPage = Me.Parent.Page.Master
            Dim rp As Telerik.Web.UI.RadPersistenceManager = mstr.FindControl("RadPersistenceManager1")
            rp.SaveState()
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function
 
    Public Function LoadTelerikPF() As Boolean
        Try
            Dim mstr As MasterPage = Me.Parent.Page.Master
            Dim rp As Telerik.Web.UI.RadPersistenceManager = mstr.FindControl("RadPersistenceManager1")
            rp.LoadState()
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function
 
    Protected Sub SaveGridSettings(sender As Object, e As EventArgs)
        SaveTelerikPF()
    End Sub
 
    Protected Sub RadMenu1_ItemClick(sender As Object, e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemClick
 
        Dim intArray(rgInventoryEdit.SelectedItems.Count - 1) As Integer
        Dim intCount As Integer = 0
 
        For Each row As GridItem In rgInventoryEdit.SelectedItems
            intArray(intCount) = rgInventoryEdit.MasterTableView.Items(row.ItemIndex).GetDataKeyValue("InventoryID")
            intCount += 1
        Next
 
        Dim strGUID As String = Guid.NewGuid.ToString
        Session(strGUID) = intArray
 
        Select Case e.Item.Text
 
 
            Case "Increase Prices"
                RadWindowManager1.Windows(0).Title = "Increase Prices"
                RadWindowManager1.Windows(0).Height = 300
                RadWindowManager1.Windows(0).Width = 600
                RadWindowManager1.Windows(0).Left = 150
                RadWindowManager1.Windows(0).NavigateUrl = "~/UserControls/PartEditDialogs/IncreasePrice.aspx?sesKey=" + Server.HtmlEncode(strGUID)
                RadWindowManager1.Windows(0).VisibleOnPageLoad = True          
 
            Case "Do Multiple Operations"
 
        End Select
 
    End Sub
End Class




Here is the aspx page that opens up in the Radwindow.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="IncreasePrice.aspx.vb" Inherits="UserControls_PartEditDialogs_IncreasePrice" Theme="SkinFile" StylesheetTheme="SkinFile" %>
<style type="text/css">
    .auto-style1 {
        width: 348px;
    }
</style>
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock2">
 
        <script 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;  
    }  
</script>
 
    </telerik:RadCodeBlock>
 
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
            AsyncPostBackTimeout="3600"/>
 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        </telerik:RadAjaxManager>
        <telerik:RadProgressManager ID="RadProgressManager1" Runat="server" />
         
         
        <div>
 
            <table>
                <tr>
                    <td style="text-align: right">
                        <asp:Label ID="Label1" runat="server" SkinID="stdLabel" Text="Amount to add to Retail :"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="tbRetail" runat="server" Width="50px">0</asp:TextBox>
                    </td>
                    <td class="auto-style1">
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="tbRetail" ErrorMessage="Please enter an amount between 0 and 1000" MaximumValue="1000" MinimumValue=".01"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <asp:Label ID="Label2" runat="server" SkinID="stdLabel" Text="Amount to add to Wholesale :"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="tbWholesale" runat="server" Width="50px">0</asp:TextBox>
                    </td>
                    <td class="auto-style1">
                        <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="tbWholesale" ErrorMessage="Please enter an amount between 0 and 1000" MaximumValue="1000" MinimumValue=".01"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <asp:Button ID="btnSetPrices" runat="server" Text="Adjust Prices" />
                    </td>
                    <td> </td>
                    <td class="auto-style1"> </td>
                </tr>
            </table>
 
        </div>
 
        <asp:PlaceHolder ID="phCloseWindow" runat="server">
            <script>
                var oWin = GetRadWindow();
                var parentWindow = oWin.BrowserWindow;
                oWin.close();
                parentWindow.refreshGrid();
                
            </script>
        </asp:PlaceHolder>
 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Width="600px" Height="300px" Runat="server" IsSticky="True" MinDisplayTime="1000" Skin="Default">
        </telerik:RadAjaxLoadingPanel>
        <div style="position:absolute;z-index:1000;top:10px;left:10px">
             <telerik:RadProgressArea ID="RadProgressArea1" runat="server" Skin="WebBlue" HeaderText="Current Progress" ProgressIndicators="FilesCountBar, CurrentFileName, TimeElapsed">
                   <Localization Uploaded="Uploaded" CurrentFileName="" UploadedFiles=""></Localization>
                </telerik:RadProgressArea>
        </div>
         
         
         
    </form>
</body>
</html>


Here is the code behind.

Imports Telerik.Web.UI
Imports System.Threading
 
Partial Class UserControls_PartEditDialogs_IncreasePrice
    Inherits System.Web.UI.Page
 
    Protected Sub UserControls_PartEditDialogs_IncreasePrice_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            phCloseWindow.Visible = False
        End If
 
    End Sub
 
    Protected Sub btnSetPrices_Click(sender As Object, e As EventArgs) Handles btnSetPrices.Click
        Dim sesKey As String = Request.QueryString("sesKey")
        Dim invArray As Integer() = Session(sesKey)
        Dim bolSuccess As Boolean = True
        Dim strWarning As String = ""
 
        For Each intID As Integer In invArray
            Label1.Text += intID.ToString + vbCrLf
        Next
 
        Dim progress As RadProgressContext = RadProgressContext.Current
        progress.Speed = "N/A"
        progress.CurrentOperationText = "Part 1 of " + invArray.Count.ToString
        RadProgressArea1.Localization.CurrentFileName = "Re-Pricing Parts : "
        progress.OperationComplete = False
 
        Dim intProgress As Integer = 0
 
        For Each intInventoryID As Integer In invArray
            Thread.Sleep(1000)
            intProgress += 1
            progress.TimeEstimated = (invArray.Count - intProgress) * 100
            progress.CurrentOperationText = "Part " + intProgress.ToString() + " of " + invArray.Count.ToString
        Next
 
        phCloseWindow.Visible = bolSuccess
        progress.OperationComplete = True
 
    End Sub
End Class


1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 10 Jan 2014, 02:06 PM
Hello Pat,

The issue stems from the fact that the VisibleOnPageLoad property of the RadWindow is used. It will cause it to reopen with every page postback. In order to open the window from the server I advise that you examine the following help article: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html. It will show you a JavaScript registration approach that will not have this shortcoming, or you could use the other suggestion and disable the ViewState of the control.

You may also find useful this help article on the different ways to open a RadWindow: http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html. If possible for your scenario, you could use only the client-side click on the menu to show the RadWindow. This will spare an unnecessary postback if it has no other purpose than to show the RadWindow.


Regards,
Marin Bratanov
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Pat Huesers
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or