Javascript Find RadWindow is null

5 posts, 0 answers
  1. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 14 Mar 2012 Link to this post

    What I am trying to do is pass a value from my RadGrid to my RadWindow when a button is clicked, very similar to what is demonstrated in this demo: 

    The trouble I have is finding my RadWindow via Javascript. Every method I try results in a null object returned from the find command. The most recent method I tried was registering the javascript as a startup script. I'm not sure what exactly I'm doing wrong. See my code below:


    <telerik:RadGrid ID="durationGrid" runat="server" DataSourceID="durationDataSource"
             OnItemCommand="durationGrid_ItemCommand" AllowPaging="true" OnItemCreated="durationGrid_ItemCreated">
                <MasterTableView runat="server" CommandItemDisplay="Top" UseAllDataFields="true" AutoGenerateColumns="false" DataKeyNames="ID">
                        <telerik:GridBoundColumn DataField="Stat" HeaderText="Status" SortExpression="Stat" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="ItemName" HeaderText="Name" SortExpression="ItemName" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="PartNumber" HeaderText="Part Number" SortExpression="PartNumber" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="Serial" HeaderText="Serial #" SortExpression="Serial" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="LotNumber" HeaderText="Lot #" SortExpression="LotNumber" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="CrossRefID" HeaderText="PS #" SortExpression="CrossRefID" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="OEM" HeaderText="OEM" SortExpression="OEM" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="Consigned" HeaderText="Consigned" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="location" HeaderText="Location" SortExpression="location" ReadOnly="true" />
                        <telerik:GridBoundColumn DataField="Value" HeaderText="Value" SortExpression="Value" ReadOnly="true" DataFormatString="{0:c}" />
                        <telerik:GridBoundColumn DataField="ExpirationDate" HeaderText="Expiration Date" SortExpression="ExpirationDate" ReadOnly="true" DataFormatString="{0:MM/dd/yyy}" />
                        <telerik:GridTemplateColumn HeaderText="">
                                    <asp:ImageButton ID="NotesBtn" runat="server" ImageUrl="images/icons/notes.png" OnClick="NotesBtn_Click"  />
                    <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" />
                <ExportSettings FileName="Duration Report"></ExportSettings>
            <telerik:RadWindowManager ID="winma2" runat="server">
                     <telerik:RadWindow ID="NotesWindow" runat="server" Modal="true" Behaviors="Close, Move"
                        Width="540px" Height="490px" DestroyOnClose="false" VisibleStatusbar="false" ShowContentDuringLoad="false" ReloadOnShow="true"
                        Skin="Simple" OnClientShow="OnClientShow" Title="Item Notes Editor" >    


    protected void NotesBtn_Click(object sender, EventArgs e)
              string script = "function openRadWin(value) {var win = $find('" + NotesWindow.ClientID + "');alert(win); Sys.Application.remove_load(openRadWin);}Sys.Application.add_load(openRadWin);";
              ScriptManager.RegisterStartupScript(this, this.GetType(), "key", script, true);
          protected void durationGrid_ItemCreated(object sender, GridItemEventArgs e)
              if (e.Item is GridCommandItem)
                  Button btncmd = (e.Item as GridCommandItem).FindControl("ExportToExcelButton") as Button;
                  if (btncmd != null)
              if (e.Item is GridDataItem)
                  ImageButton NotesBtn = (ImageButton)e.Item.FindControl("NotesBtn");
                  NotesBtn.OnClientClick = "openRadWin('" + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + "');";

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

    Posted 14 Mar 2012 Link to this post

    Hello William,

    Try  the following approach to open the window from server side.

    protected void NotesBtn_Click(object sender, ImageClickEventArgs e)
        string ShowWindow = "ShowWindow();";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowWindow", ShowWindow, true);

    <script type="text/javascript">
      function ShowWindow()
          var oWnd = $find("<%=NotesWindow.ClientID%>");
          // . . . .

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 14 Mar 2012 Link to this post

    I tried implementing your code, but no luck opening the window. I modified the javascript to add an alert to tell me what the value of oWnd was [alert(oWnd);], and it's returning null. 
  5. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 14 Mar 2012 Link to this post

    I ended up just putting the javascript at the end of the page. Now it finds the control. Thanks for your help.
  6. Zhuoyun
    Zhuoyun avatar
    5 posts
    Member since:
    Jan 2014

    Posted 09 May 2014 Link to this post

    Same here. Have to put the js function on the same page.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017