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

RadGrid Control step-through after postback

3 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 01 Dec 2010, 09:53 PM
First, let me point out that the code works perfectly on the first load. However, on the postback, the Telerik controls are not ready yet.

So I'm doing a simple loop through the grid:

var tempValue = new Array(0, 0, 0, 0, 0, 0, 0, 0);
var senderId = sender.get_id();
var telerikControl;
var grid = $find("<%= uxGrid.ClientID %>");
var rows = grid.get_masterTableView().get_dataItems();
var rowCount = rows.length; // make loop run faster
for (i = 0; i < rowCount; i++) { // foreach row
    for (j = 1; j <= 7; j++) {
        console.log(rows[i].get_element());
        telerikControl = rows[i].findControl('uxHours' + j);
        if (telerikControl == null) {
            console.log('could not find control "uxHours' + j + '" in row ' + i
                + '; updateDaySummaries initiated by ' + senderId);
        }
        if (telerikControl.get_value().length != 0) { // do NOT use greater than
            //console.log('adding ' + telerikControl.get_value() + ' from ' + telerikControl.get_id() + ' to tempValue[' + (j - 1) + ']:' + tempValue[j - 1]);
            tempValue[j - 1] += telerikControl.get_value();
        }
    }
}

See the line where I call console.log(rows[i].get_element()); ?

Here is a sample of the difference between the first page load (which works) and the postback.

broken code (line 83):
<div style="z-index: 6000;" class="rcbSlide"><div style="display: none; width: 175px;" class="RadComboBoxDropDown RadComboBoxDropDown_Default " id="ctl00_bodyContentPlaceHolder_uxContainer_uxGrid_ctl00_ctl04_uxServiceList_dropDown_DropDown"><div style="height: 150px; width: 100%;" class="rcbScroll rcbWidth"><ul style="list-style: none outside none; margin: 0pt; padding: 0pt;" class="rcbList"><li class="rcbItem ">Business Development</li></ul></div></div></div><input type="hidden" name="ctl00_bodyContentPlaceHolder_uxContainer_uxGrid_ctl00_ctl04_uxServiceList_dropDown_ClientState" id="ctl00_bodyContentPlaceHolder_uxContainer_uxGrid_ctl00_ctl04_uxServiceList_dropDown_ClientState" autocomplete="off" value="{"logEntries":[],"value":"16","text":"Business Development","enabled":true}">

working code (line 83):
<input type="hidden" name="ctl00_bodyContentPlaceHolder_uxContainer_uxGrid_ctl00_ctl04_uxServiceList_dropDown_ClientState" id="ctl00_bodyContentPlaceHolder_uxContainer_uxGrid_ctl00_ctl04_uxServiceList_dropDown_ClientState" autocomplete="off" value="{"logEntries":[],"value":"16","text":"Business Development","enabled":true}">

Any ideas?




3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 07 Dec 2010, 12:37 PM
Hello Brad,

Could you please elaborate a bit more on your scenario. Do you have any ajax settings on the page? When do you execute the posted javascript code - when page loads or when the user perform any action, for example clicks button? Additionally it will be helpful if you could post your aspx page markup declaration with the related code behind. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

Looking forward for your reply.

Greetings,
Radoslav
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Brad
Top achievements
Rank 1
answered on 07 Dec 2010, 07:20 PM
The event fires on the OnGridCreated client event on the RadGrid

<
ClientEvents OnGridCreated="updateDaySummaries" />

The problem happens after a postback resulting from a button click. There is nothing wrong with the data that is being bound to the control. The page looks and acts fine except for this one thing.

Yes, the page uses Ajax.

When I fire the method on page load (below), I get, "grid is null".
if (!ClientScript.IsClientScriptBlockRegistered("updateDaySummaries"))
{
    ClientScript.RegisterClientScriptBlock(this.GetType(), "updateDaySummaries""$(document).ready(function () {log('<--- you are here.');updateDaySummaries(this);});"true);
}

However, if I fire the event from a button (OnClientClick) everything works fine.

ALSO!

If I fire the script like so, it works.
        $(document).ready(function () {
            setTimeout('updateDaySummaries();', 0);
        });
This is my work-around. Mark as answer.
0
Iana Tsolova
Telerik team
answered on 10 Dec 2010, 04:36 PM
Hi Brad,

The reason for the error message is that $(document).ready is fired too early and the controls client objects are still not created. Therefore you can move the code from it to the pageLoad client-side event of the PageRequestManager.

Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Brad
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or