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

Javascript not firing after Postback when Telerik Grid is placed within User Control

9 Answers 384 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshan
Top achievements
Rank 1
Joshan asked on 04 Mar 2012, 03:42 PM
I have been perusing the forum for nearly 2 days but have not found a solution. I have a Telerik Grid placed within a user control. After a Postback, the client side events do not fire, neither a row click javascript or my own custom "alert('Hi')" javascript. But when i place the same code within a .aspx page, it works perfectly. Could the support team please throw some light on this. My entire application runs on user controls so I cannot avoid using it!!!

9 Answers, 1 is accepted

Sort by
0
Joshan
Top achievements
Rank 1
answered on 06 Mar 2012, 08:15 AM
mild bounce... please help...
0
Maria Ilieva
Telerik team
answered on 07 Mar 2012, 05:52 PM
Hello,

Could you please elaborate a bit more on your application.
Are you using Ajax for loading the UserControls? If yes note that  there are some specifics in executing custom javascript after ajax request. Review the help topic below for more information on this matter:
http://www.telerik.com/help/aspnet-ajax/ajax-execute-custom-javascript.html

 Also pleas note that the dynamic loaded user controls should be recreated on each postback, not only on initial page load.


Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Elliott
Top achievements
Rank 2
answered on 07 Mar 2012, 05:57 PM
stupid, but it happened to me...
is there a script on your user control throwing exceptions?
look for the yellow triangle at the bottom of the page
script error -> nothing else works i.e. rich Telerik client functionality.....
0
Joshan
Top achievements
Rank 1
answered on 08 Mar 2012, 11:35 AM
Im facing the same issue as given in this forum ( http://www.telerik.com/community/forums/aspnet-ajax/grid/get-mastertableview-throwing-error.aspx )... the javascript is actually firing but the $find(grid's client id) is returning null....

not sure why a postback returns a null grid client object.... 
0
Casey
Top achievements
Rank 1
answered on 08 Mar 2012, 02:19 PM
Hi Joshan,

Could you please post your javascript and RadGrid definition? It would help with identifying what is going on. 

Thanks!
Casey
0
Joshan
Top achievements
Rank 1
answered on 20 Mar 2012, 06:48 AM
Casey,

here is my design source:


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MessageInbox.ascx.cs"
    Inherits="WealthERP.Messages.MessageInbox" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

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

    <script type="text/javascript">
        function checkAllBoxes() {
            //get total number of rows in the gridview and do whatever
            //you want with it..just grabbing it just cause
            var grid = $find("ctrl_MessageInbox_RadGrid1");
            alert(grid);
            var MasterTable = grid.get_masterTableView();
            var Rows = MasterTable.get_dataItems();
            //debugger;
            var totalRows = Rows.length;
            var hdrChkBx = document.getElementById("hdrCheckBox");
            
            for (var i = 0; i < totalRows; i++) {
                var chkbx = Rows[i].findElement("chkbxRow");
                chkbx.checked = hdrChkBx.checked;
            }
        }
    </script>


</telerik:RadScriptBlock>


<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />

<table class="TableBackground" width="100%">
<tr id="trContent" runat="server">
<td>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" EnablePageHeadUpdate="false">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                            <telerik:AjaxUpdatedControl ControlID="pnlMessage" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Office2007" />
<div id="dv" class="dvInbox">
<telerik:RadGrid ID="RadGrid1" runat="server" Width="860px" Height="250px" PageSize="6"
                    AllowPaging="True" ShowGroupPanel="true" GridLines="None" AutoGenerateColumns="False"
                    Style="border: 0; outline: none;" Skin="Telerik" EnableEmbeddedSkins="false"
                    OnItemCommand="RadGrid1_ItemCommand" EnableViewState="true" OnNeedDataSource="RadGrid1_NeedDataSource"
                    OnItemDataBound="RadGrid1_ItemDataBound">
                    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                    <MasterTableView DataKeyNames="MR_MessageRecipientId" ShowFooter="true">
                        <Columns>
                            <telerik:GridTemplateColumn UniqueName="TemplateColumn1" Groupable="False">
                                <HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
                                <HeaderTemplate>
                                    <input type="checkbox" id="hdrCheckBox" onclick="checkAllBoxes()" />
                                </HeaderTemplate>
                                <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkbxRow" runat="server" />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:LinkButton ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" ForeColor="White" />
                                </FooterTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="TemplateColumn1" Groupable="False">
                                <HeaderStyle Width="30px"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                <ItemTemplate>
                                    <img src='<%# Boolean.Parse(DataBinder.Eval(Container.DataItem, "IsReadByUser").ToString())? "../Images/Telerik/mailOpenIcon.png":"../Images/Telerik/mailNewIcon.png" %>'
                                        alt="MailIcon" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn UniqueName="From" HeaderText="From" DataField="Sender">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="Subject" HeaderText="Subject" DataField="Subject">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="Received" SortExpression="Received" HeaderText="Received"
                                DataField="SentOn" DataFormatString="{0:d}">
                                <HeaderStyle Width="125px"></HeaderStyle>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="ReadByUser" DataField="IsReadByUser" Visible="false" />
                            <telerik:GridButtonColumn ButtonType="LinkButton" Text="Read" CommandName="Read">
                            </telerik:GridButtonColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

</div>
</td>
</tr>
</table>

====================================================

I am calling the checkAllBoxes() function to check all boxes in the grid to implement delete functionality. But on postback (paging included), the $find(grid's client id) is returning null....

0
Casey
Top achievements
Rank 1
answered on 21 Mar 2012, 03:32 PM
Joshan,

I normally reference a RadGrid in a javascript function as follows:

function checkAllBoxes(){
    var grid = $find("<%= RadGrid1.ClientID %>");
}

I hope this helps!
Casey
0
Joshan
Top achievements
Rank 1
answered on 23 Mar 2012, 05:56 AM
Casey,

<%= RadGrid1.ClientID %>  translates to the 'ctrl_MessageInbox_RadGrid1' that I have used...

Anyways, I have tried this too just in case I have typed in the wrong client id.... But the grid object still throws null after a postback...
Any clue???

0
Maria Ilieva
Telerik team
answered on 27 Mar 2012, 12:36 PM
Hi Joshan,

Could you please try to set a minor TimeOut on executing the problematic function and verify if this will make any deference.


Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Joshan
Top achievements
Rank 1
Answers by
Joshan
Top achievements
Rank 1
Maria Ilieva
Telerik team
Elliott
Top achievements
Rank 2
Casey
Top achievements
Rank 1
Share this question
or