Ajax Request Null reference Error

3 posts, 1 answers
  1. Akhil Raj
    Akhil Raj avatar
    69 posts
    Member since:
    Aug 2012

    Posted 08 Feb 2010 Link to this post

    hi all,
      I want to filter grid accoridng to the textbox value. I initiate ajax request in 'keyup' client event of textbox and write filter code in the ajax request event. But when i added ajax settings for reax requestmanager i shoing dome null refernce script error. Can anyone give me what i did wrongly?

    Check the attached file for error screenshot

    Design Code :
    <body> 
        <form id="form1" runat="server" dir="ltr">  
                <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
                    <script type="text/javascript">  
                        var timer = null;  
     
                        function KeyUp() {  
                            if (timer != null) {  
                                clearTimeout(timer);  
                            }  
                            timer = setTimeout(LoadTable, 100);  
                        }  
     
                        function LoadTable() {  
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("SearchGrid");  
                        }  
                    </script> 
                </telerik:RadCodeBlock> 
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
            </telerik:RadScriptManager> 
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" IsSticky="true"    
                Skin="Default">  
            </telerik:RadAjaxLoadingPanel> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"   
                UpdatePanelsRenderMode="Inline" DefaultLoadingPanelID="RadAjaxLoadingPanel1"   
                onajaxrequest="RadAjaxManager1_AjaxRequest">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_Resource" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                  
                    <telerik:AjaxSetting AjaxControlID="rad_ts_Main">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_ts_Main" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_mp_Main" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                   <telerik:AjaxSetting AjaxControlID="btn_GetFiles">  
                        <UpdatedControls> 
                             <telerik:AjaxUpdatedControl ControlID="RadAjaxManager1" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_cmb_FileName" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_cmb_Language" /> 
                            <telerik:AjaxUpdatedControl ControlID="btn_LoadResource" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_Resource" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                    <telerik:AjaxSetting AjaxControlID="rad_cmb_FileName">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_cmb_Language" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                    <telerik:AjaxSetting AjaxControlID="btn_LoadResource">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_Resource" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_cmb_Filter" /> 
                            <telerik:AjaxUpdatedControl ControlID="btn_AddKeys" /> 
                            <telerik:AjaxUpdatedControl ControlID="btn_Save" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                     <telerik:AjaxSetting AjaxControlID="rad_cmb_Filter">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_Resource" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting>                 
                    <telerik:AjaxSetting AjaxControlID="btn_AddKeys">  
                        <UpdatedControls> 
                           <telerik:AjaxUpdatedControl ControlID="rad_mp_Main" /> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_NewKeys" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                    <telerik:AjaxSetting AjaxControlID="btn_Save">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rad_grd_Resource"   
                                LoadingPanelID="RadAjaxLoadingPanel1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
           
         <telerik:RadTabStrip ID="rad_ts_Main" runat="server" MultiPageID="rad_mp_Main"   
                ontabclick="rad_ts_Main_TabClick"  > 
            <Tabs> 
                <telerik:RadTab runat="server" PageViewID="pv_Editor" Text="Resource Editor"   
                    Selected="True"></telerik:RadTab> 
                <telerik:RadTab runat="server" PageViewID="pv_NewKey" Text="New Keys"></telerik:RadTab> 
            </Tabs> 
        </telerik:RadTabStrip> 
         <telerik:RadMultiPage ID="rad_mp_Main" runat="server" SelectedIndex="0">  
            <telerik:RadPageView ID="pv_Editor" runat="server">  
                <table width="98%"  > 
                <tr> 
                    <td colspan="3" width="90%">  
                        <asp:TextBox ID="txt_Directory" runat"server" Width="500px" ></asp:TextBox>   
                        <asp:Button ID="btn_GetFiles" runat="server" Text="Get Resources" OnClick="btn_GetFiles_onClick" /> 
                    </td> 
                    <td width="10%" align="right">  
                        <telerik:RadTextBox ID="rad_txt_Search" runat="server" SelectionOnFocus="CaretToEnd" EmptyMessage="Search" onkeyup="KeyUp();"></telerik:RadTextBox> 
                    </td> 
                </tr> 
                <tr> 
                <td width="40%">  
                    Select Resource : <telerik:RadComboBox ID="rad_cmb_FileName" runat="server" AutoPostBack="true" Width="230px"   
                        onselectedindexchanged="rad_cmb_FileName_SelectedIndexChanged">  
                    </telerik:RadComboBox>          
                </td> 
                <td width="32%" > 
                    Language : <telerik:RadComboBox ID="rad_cmb_Language" runat="server" Width="200px" > 
                    </telerik:RadComboBox>          
                      
                </td> 
                <td width="18%" align="right">  
                    <asp:Button ID="btn_LoadResource" runat="server" Text="Load Rosource" OnClick="btn_LoadResource_onClick" /><br /> 
                </td> 
                <td width="10%">  
                    <telerik:RadComboBox ID="rad_cmb_Filter" runat="server" AutoPostBack="true" Width="130px" onselectedindexchanged="rad_cmb_Filter_SelectedIndexChanged"></telerik:RadComboBox> 
                </td> 
                </tr> 
                <tr> 
                    <td colspan="4">  
                        <asp:Label ID="lblError" runat"server" ForeColor="Red" Font-Size="Small"></asp:Label> 
                    </td> 
                </tr> 
                <tr> 
                <td colspan="4">  
                    <telerik:RadGrid ID="rad_grd_Resource" runat="server"   
                        AutoGenerateColumns="false" Height="360"   
                        onitemdatabound="rad_grd_Resource_ItemDataBound"   
                        onitemcreated="rad_grd_Resource_ItemCreated"   
                        onprerender="rad_grd_Resource_PreRender" > 
                    <ClientSettings > 
                    <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
                    </ClientSettings> 
                        <MasterTableView > 
                            <Columns> 
                                <telerik:GridTemplateColumn UniqueName="Key" HeaderText="Key" DataType="System.String" > 
                                    <ItemTemplate> 
                                        <asp:Label ID="lbl_it_Key" runat="server" Width="75%" Text='<%#Eval("Key") %>'></asp:Label> 
                                    </ItemTemplate> 
                               </telerik:GridTemplateColumn> 
                                <telerik:GridTemplateColumn UniqueName="ValueDefault" HeaderText="Value - Default" > 
                                    <ItemTemplate> 
                                        <asp:TextBox ID="txt_it_ValueDefault" runat="server" Width="75%" Text='<%#Eval("ValueDefault") %>'></asp:TextBox> 
                                    </ItemTemplate> 
                              </telerik:GridTemplateColumn> 
                                <telerik:GridTemplateColumn UniqueName="Value" HeaderText="Value" > 
                                    <ItemTemplate> 
                                        <asp:TextBox ID="txt_it_Value" runat="server" Width="75%" Text='<%#Eval("Value") %>'></asp:TextBox> 
                                    </ItemTemplate> 
                                </telerik:GridTemplateColumn> 
                                
                            </Columns> 
                            <NoRecordsTemplate> 
                            </NoRecordsTemplate> 
                        </MasterTableView> 
                         
                    </telerik:RadGrid> 
                </td> 
                </tr> 
                <tr> 
                <td width="40%">&nbsp;</td> 
                <td width="32%">&nbsp;</td> 
                <td colspan="2" width="28%" align = "right">  
                    <asp:Button ID="btn_AddKeys" runat="server" Text="Add New Keys" OnClick="btn_AddKeys_onClick" /> 
                    <asp:Button ID="btn_Save" runat="server" Text="Save" OnClick="btn_Save_onClick" /> 
                </td> 
                </tr> 
                </table> 
            </telerik:RadPageView> 
            <telerik:RadPageView ID="pv_NewKey" runat="server">  
                <table width="100%">  
                    <tr> 
                    <td width="70%">  
                        <asp:Label ID="lblErrorKeys" runat"server" ForeColor="Red" Font-Size="Small"></asp:Label> 
                    </td> 
                    <td width="30%">  
                        Page Prefix : <telerik:RadTextBox ID="rad_txt_PagePrefix" runat="server"></telerik:RadTextBox> 
                    </td> 
                    </tr> 
                    <tr> 
                        <td colspan="2">  
                            <telerik:RadGrid ID="rad_grd_NewKeys" runat="server"   
                                AutoGenerateColumns="false" Width="98%" Height="400px"   
                                onitemcommand="rad_grd_NewKeys_ItemCommand"   
                                oneditcommand="rad_grd_NewKeys_EditCommand"   
                                oncancelcommand="rad_grd_NewKeys_CancelCommand"   
                                onupdatecommand="rad_grd_NewKeys_UpdateCommand" > 
                                <MasterTableView ShowFooter="true" EditMode="InPlace" > 
                                    <Columns> 
                                        <telerik:GridTemplateColumn UniqueName="NewKey" HeaderText="Key" HeaderStyle-Width="50%" > 
                                            <ItemTemplate> 
                                                <asp:Label ID="lbl_it_Key" runat="server" Width="75%" Text='<%#Eval("Key") %>'></asp:Label> 
                                            </ItemTemplate> 
                                            <FooterTemplate> 
                                                <asp:TextBox ID="txt_ft_Key" runat="server" Width="75%" ></asp:TextBox> 
                                            </FooterTemplate> 
                                        </telerik:GridTemplateColumn> 
                                        <telerik:GridTemplateColumn UniqueName="NewValue" HeaderText="Value"  HeaderStyle-Width="35%" > 
                                            <ItemTemplate> 
                                                <asp:Label ID="txt_it_Value" runat="server" Width="75%" Text='<%#Eval("Value") %>'></asp:Label> 
                                            </ItemTemplate> 
                                            <EditItemTemplate> 
                                                 <telerik:RadTextBox ID="rad_txt_et_Value" runat="server" Width="200px" ></telerik:RadTextBox> 
                                            </EditItemTemplate>    
                                            <FooterTemplate> 
                                                <asp:TextBox ID="txt_ft_Value" runat="server" Width="75%" ></asp:TextBox> 
                                            </FooterTemplate> 
                                        </telerik:GridTemplateColumn> 
                                        <telerik:GridTemplateColumn UniqueName="AddKeyColumn" HeaderText="Edit"  HeaderStyle-Width="15%">  
                                        <ItemTemplate> 
                                            <asp:LinkButton ID="lnkbtn_it_Edit" runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton> 
                                        </ItemTemplate> 
                                        <EditItemTemplate> 
                                            <asp:LinkButton ID="lnkbtn_et_Update" runat="server" CommandName="Update" Text="Update"></asp:LinkButton> 
                                            <asp:LinkButton ID="lnkbtn_et_Cancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
                                        </EditItemTemplate> 
                                        <FooterTemplate> 
                                            <asp:Button ID="btn_ft_Insert" runat="server" CommandName="AddKey" Text="Add" /> 
                                        </FooterTemplate> 
                                        </telerik:GridTemplateColumn> 
                                          
                                    </Columns> 
                                    <NoRecordsTemplate> 
                                    </NoRecordsTemplate> 
                                </MasterTableView> 
                                 
                            </telerik:RadGrid> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td width="80%">&nbsp;</td> 
                        <td width="20%">  
                            <asp:Button ID="btn_SaveKeys" runat="server" Text="Save" OnClick="btn_SaveKeys_onClick" /> 
                        </td> 
                    </tr> 
                </table> 
            </telerik:RadPageView> 
         </telerik:RadMultiPage> 
           
         </form> 
    </body> 
    Code Behind:
            protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
            {  
                if (e.Argument.IndexOf("SearchGrid") != -1)  
                {  
                    rm.BindGrid(rad_grd_Resource, rad_cmb_Language.SelectedValue, rad_txt_Search.Text, lblError);  
                }  
     
            } 
  2. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 10 Feb 2010 Link to this post

    Hi Akhil,

    It is difficult to say what the exact reason for the exception is, however, I suppose it is due to the way your ajax settings are declared. Please, keep in mind that when you ajaxify a control (let's say the grid) through a another control(let's say a button), the RadAjaxManager puts an UpdatePanel around the first control (the grid). In you case, you have added first an ajax setting for the grid which means that you get one UpdatePanel rendered around the grid. Then you are adding ajax settings for the MultiPage where the grid resides. This puts an UpdatePanel around the MultiPage - the grid's container, and thus the final result is an UpdatePanel wrapped in an UpdatePanel. In most cases, this bound to break the ajax request.

    Therefore, when you have a grid in a MultiPage try ajaxifying the MultiPage only.

    I hope this helps.

    All the best,
    Tsvetoslav
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Akhil Raj
    Akhil Raj avatar
    69 posts
    Member since:
    Aug 2012

    Posted 11 Feb 2010 Link to this post

    thanks admin...i changed update control id to multipage and working fine.
Back to Top