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

Using RadWindow and returning values in MOSS 2007

3 Answers 64 Views
Window
This is a migrated thread and some comments may be shown as answers.
JFr
Top achievements
Rank 1
JFr asked on 25 Jan 2010, 08:14 AM
Hello everyone,

I am trying to open a RadWindow from a custom field type and return a value from the user.  The window is supposed to be opened from the custom field (see openSearchDialogButton below) that is implemented as a user control (CustomControl.ascx in ControlTemplates).  The code for this control is encapsulated in an assembly deployed to the GAC.

The user control is defined as follows:

<%@ Control Language="C#" Debug="True" %> 
 
<%@ Assembly Name="Pl.ContractCenter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d55543c9f6e51cd" %> 
<%@ Assembly Name="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> 
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%> 
<%@ Register Assembly="Telerik.Web.UI, Version=2009.1.402.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<SharePoint:RenderingTemplate ID="PlSearchFieldControl" runat="server"
    <Template> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager> 
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
            <script language="javascript" type="text/javascript"
                //<![CDATA[
                function openWin() {
                    var oWnd = radopen("/_layouts/PlSearchCompanyForm.aspx", "RadWindow1");
                }

                function OnClientClose(oWnd, args) {
                    var arg = args.get_argument();
                    if (arg) {
                        var companyNo = arg.companyNo;
                        var o = $get(txtAddValueId); // set in code-behind
                        if (o)
                            o.value = companyNo;
                    }
                }
                //]]> 
            </script> 
        </telerik:RadCodeBlock> 
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" EnableAJAX="true" > 
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="btnAdd"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="companyNo" /> 
                        <telerik:AjaxUpdatedControl ControlID="companyName" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="deleteButton"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="companyNo" /> 
                        <telerik:AjaxUpdatedControl ControlID="companyName" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager>             
        <telerik:RadAjaxPanel runat="server"
            <asp:GridView ID="grdChoices" runat="server" Width="90%" AutoGenerateDeleteButton="True" ShowHeader="false" BorderWidth="0" BorderStyle="None"
                <RowStyle CssClass="ms-vb2" /> 
            </asp:GridView> 
        </telerik:RadAjaxPanel> 
        <br /> 
        <runat="server" ID="openSearchDialogButton" onclick="openWin(); return false;"><img src="/_layouts/images/gosearch.gif" runat="server" id="imgSearch" border="0" alt="search" /></a
        <asp:TextBox CssClass="ms-input" ID="txtAddValue" runat="server"/> 
        <asp:Button CssClass="ms-input" ID="btnAdd" runat="server" Text="Add" /><br /> 
        <asp:CustomValidator ID="validGlobal" runat="server" Display="Dynamic"></asp:CustomValidator> 
        <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" runat="server" Skin="Sunset"
            <Windows> 
                <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" NavigateUrl="/_layouts/PlSearchCompanyForm.aspx" Width="600" Height="500"></telerik:RadWindow> 
            </Windows> 
        </telerik:RadWindowManager> 
    </Template> 
</SharePoint:RenderingTemplate> 

The page loaded within the RadWindow has the following definition:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Pl.ContractCenter.UI.Pages.SearchCompanyForm, Pl.ContractCenter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d55543c9f6e51cd" %> 
<%@ Assembly Name="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> 
<%@ Register Assembly="Telerik.Web.UI, Version=2009.1.402.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
<!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 runat="server"
        <title>Search for Companies</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager> 
            <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1" > 
                <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(companyNo) { 
                        var oArg = new Object(); 
                        oArg.companyNo = companyNo; 
                        var oWnd = GetRadWindow(); 
                         
                        if(oArg.companyNo) { 
                            oWnd.close(oArg); 
                        } 
                    } 
                </script> 
            </telerik:RadCodeBlock> 
            <div> 
                <telerik:RadTextBox runat="server" ID="searchTextBox" />  
                <asp:Button runat="server" ID="searchButton" onclick="searchButton_Click" /> 
                <telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="odsCompany" AutoGenerateColumns="False" GridLines="None" AllowPaging="True" onitemdatabound="RadGrid1_ItemDataBound">             
                    <MasterTableView DataSourceID="odsCompany" DataKeyNames="CompanyNo"
                        <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="CompanyFullName" HeaderText="Company Name" SortExpression="CompanyByName" UniqueName="CompanyByName"
                            </telerik:GridBoundColumn> 
                            <telerik:GridHyperLinkColumn DataTextField="CompanyNo" HeaderText="Number" SortExpression="CompanyNo" UniqueName="CompanyNo"
                            </telerik:GridHyperLinkColumn> 
                        </Columns> 
                    </MasterTableView>             
                </telerik:RadGrid> 
                <asp:ObjectDataSource> 
                    <%-- SNIPPED --%> 
                </asp:ObjectDataSource> 
            </div> 
        </form> 
    </body> 
</html> 

Finally, the code-behind for the page:

public class SearchCompanyForm : Page { 
        protected ObjectDataSource odsCompany; 
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { 
            try { 
                if (e.Item is GridDataItem) { 
                    var hyperLink = (e.Item as GridDataItem)["CompanyNo"].Controls[0] as HyperLink; 
 
                    if (hyperLink == null
                        return
 
                    hyperLink.NavigateUrl = "#"
                    hyperLink.Attributes.Add("OnClick", String.Format("javascript:returnToParent({0}); return false;", hyperLink.Text.Trim())); 
                } 
            } catch (Exception exception) { 
                Console.WriteLine(exception.Message); 
            } 
        } 
 
        protected void searchButton_Click(object sender, EventArgs e) { 
            odsCompany.Select(); 
        } 
    } 

Clicking the GridHyperLinkColumn returns the selected value as an argument to returnToParent.
The problem I am facing is that the call to radopen fails with the error "radopen is not defined" (Firebug).  While I've got this working in a standard ASP.NET project it just won't work with SharePoint.  Any clues?

Thank you

Steve


3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 27 Jan 2010, 02:00 PM
Hello eSGe,

If I understand the problem correctly, you get the error when you click the openSearchDialogButton link, is this so?
<a runat="server" ID="openSearchDialogButton" onclick="openWin(); return false;"><img src="/_layouts/images/gosearch.gif" runat="server" id="imgSearch" border="0" alt="search" /></a>

I am asking this because your code looks OK. We also ran it in MOSS and everything worked as expected - RadWindow was opened without errors.

In general, an error like the one that you report could happen if you don't have a RadWindowManager present on the page when you call radopen(), but in your scenario you already have the RadWindowManager on the page and you don't call radopen() while the manager is still not initialized (another common cause for this error - usually happens when radopen() is called from the server).




Best wishes,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
JFr
Top achievements
Rank 1
answered on 01 Feb 2010, 06:20 AM
Hi Georgi,

Sorry for the late reply (I've been on a business trip).  That's essentially what is happening.  A click on openSearchDialogButton fails with Firebug reporting that radopen is not defined.  So far I can't figure out what's going on.  Any ideas anyone?

Thanks

Steve
0
Georgi Tunev
Telerik team
answered on 04 Feb 2010, 09:50 AM
Hello Steve,

At this point I really cannot tell what the reason for the problem might be. Could you please check if the page loads OK? I mean if there is some JavaScript error on the page (should be visible in the Firebug console) this might prevent the rest of the JS code from working as expected. Another thing that you may try is to put a standard button and try to call the window from there.
e.g.
<button onclick ="openWin(); return false">test</button>


Kind regards,
Georgi Tunev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Window
Asked by
JFr
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
JFr
Top achievements
Rank 1
Share this question
or