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

Not finding grid on Postback in window.onload

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shahryar Ali
Top achievements
Rank 1
Shahryar Ali asked on 09 Sep 2010, 11:24 PM
I am having a problem when trying to get the master table view of a grid in a window.onload function.  It works fine when the form first loads, but failes to find the grid on the postback.

Here's the javascript:

 

 

 

 

 

 

 

 

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">

 

 

 

<script type="text/javascript" >

 


window.onload =

 

function () {

 

 

   var masterTable = $find("<%= radGridCashFlows.ClientID 
%>").get_masterTableView();
   masterTable.selectItem(masterTable.get_dataItems()[0].get_element());

 And here's the grid control:

 

 

 

<telerik:RadGrid ID="radGridCashFlows" runat="server" Width="520px" Height="135px" Skin="Default" AllowMultiRowSelection="false" >

 

 

 

<ClientSettings EnableRowHoverStyle="true" >

 

 

 

<ClientEvents OnRowClick="CFSelected" />

 

 

 

<Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true" />

 

 

 

<Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders="true" />

 

 

 

</ClientSettings>

 

 

 

<MasterTableView AutoGenerateColumns="false" Font-Size="Larger" ClientDataKeyNames="CFDesc,CFTypeDesc,CFAcctTypeName,CFID,CFTypeID,ScenTargetID,StartYear,EndYear,YearlyReqment,InflationPct" DataKeyNames="CFDesc,CFTypeDesc,CFAcctTypeName,CFID,CFTypeID,ScenTargetName" NoMasterRecordsText="No Cash Flows Created.." >

 

 

 

<Columns>

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="CFDesc"

 

 

 

HeaderText="Cash Flow Name:"

 

 

 

SortExpression="CFDesc"

 

 

 

UniqueName="CFDesc"

 

 

 

HeaderStyle-Width="140px" />

 

 

 

<telerik:GridBoundColumn

 

 

 

HeaderStyle-Width="150px"

 

 

 

DataField="CFTypeDesc"

 

 

 

HeaderText="CF Type:"

 

 

 

SortExpression="CFTypeDesc"

 

 

 

UniqueName="CFTypeDesc" />

 

 

 

<telerik:GridBoundColumn

 

 

 

HeaderStyle-Width="90px"

 

 

 

DataField="CFAcctTypeName"

 

 

 

HeaderText="Acct. Type:"

 

 

 

SortExpression="CFAcctTypeName"

 

 

 

UniqueName="CFAcctTypeName" />

 

 

 

<telerik:GridBoundColumn

 

 

 

HeaderStyle-Width="120px"

 

 

 

DataField="ScenTargetName"

 

 

 

HeaderText="Solve For:"

 

 

 

SortExpression="ScenTargetName"

 

 

 

UniqueName="ScenTargetName" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="CFID"

 

 

 

HeaderText="CFID:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="CFTypeID"

 

 

 

HeaderText="CFTypeID:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="ScenTargetID"

 

 

 

HeaderText="ScenTargetID:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="StartYear"

 

 

 

HeaderText="StartYear:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="EndYear"

 

 

 

HeaderText="EndYear:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="YearlyReqment"

 

 

 

HeaderText="YearlyReqment:"

 

 

 

Visible="false" />

 

 

 

<telerik:GridBoundColumn

 

 

 

DataField="InflationPct"

 

 

 

HeaderText="InflationPct:"

 

 

 

Visible="false" />

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

 


I am doing this so that I can fire a javascript function that sets some page characteristics based on the current grid row.  I could do this server-side, but I have the Js function written, and don't want to duplicate the logic.  Any suggestions would be appreciated.

Thanks,
Shahryar

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Sep 2010, 06:56 AM
Hello Shahryar,

Since all the ajaxified controls rendered after the window.load event, you can try your code in the reserved client side pageLoad event.

Sample Code:
<script type="text/javascript">
    function pageLoad() {
        var grid= $find("<%= RadGrid1.ClientID %>");
    }
</script>


Hope this information helps,
Princy.
0
Shahryar Ali
Top achievements
Rank 1
answered on 10 Sep 2010, 08:08 PM
That worked!  -Thanks,

Shahryar
Tags
Grid
Asked by
Shahryar Ali
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shahryar Ali
Top achievements
Rank 1
Share this question
or