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

Javascript Find RadWindow is null

4 Answers 459 Views
Window
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 14 Mar 2012, 02:16 PM
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: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid 

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:

ASPX

<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">
                <Columns>
                    <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="">
                            <ItemTemplate>
                                <asp:ImageButton ID="NotesBtn" runat="server" ImageUrl="images/icons/notes.png" OnClick="NotesBtn_Click"  />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                </Columns>
                <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" />
            </MasterTableView>
            <ExportSettings FileName="Duration Report"></ExportSettings>
        </telerik:RadGrid>
 
 
        <telerik:RadWindowManager ID="winma2" runat="server">
            <Windows>
                 <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" >    
                 </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>



C#

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)
              {
                  RadScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btncmd);
              }
 
          }
          if (e.Item is GridDataItem)
          {
              ImageButton NotesBtn = (ImageButton)e.Item.FindControl("NotesBtn");
              NotesBtn.OnClientClick = "openRadWin('" + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + "');";
          }
      }

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2012, 02:56 PM
Hello William,

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

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

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

Thanks,
Shinu.
0
William
Top achievements
Rank 1
answered on 14 Mar 2012, 03:36 PM
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. 
0
William
Top achievements
Rank 1
answered on 14 Mar 2012, 08:11 PM
I ended up just putting the javascript at the end of the page. Now it finds the control. Thanks for your help.
0
Zhuoyun
Top achievements
Rank 1
answered on 09 May 2014, 03:17 PM
Same here. Have to put the js function on the same page.
Tags
Window
Asked by
William
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
William
Top achievements
Rank 1
Zhuoyun
Top achievements
Rank 1
Share this question
or