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

'Undefined' is null or not an object

3 Answers 141 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
PJ Melies
Top achievements
Rank 1
PJ Melies asked on 22 Dec 2008, 07:15 PM
I have a web page containing a user control which itself contains another user control.  The page contains an Ajax Manager and both user controls define their own Ajax Manager Proxies.

The top level user control shows or hides the nested user control based on the value of a combo box.  The nested user control also shows or hides a text box based on the value of a combo box.  When I select the option in the combo box of the root user control to display the nested user control and then select the value of the combo box in the nested user control to display the text box in the nested user control I get a javascript "'Undifined' is null or not an object" error and I don't know why.

Here's the contents of the page (nothing in the code behind):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="WebUserControl1.ascx" TagName="uc1" TagPrefix="top" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
      
    <top:uc1 ID="UserControl1" runat="server" /> 
      
    <telerik:RadAjaxManager ID="DefaultRadAjaxManager" runat="server" />      
    </form> 
</body> 
</html> 

Here's the contents of the UserControl1:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="WebUserControl2.ascx" TagName="uc2" TagPrefix="nested" %> 
 
This controls visibility of nested user control.<br /> 
<telerik:RadComboBox ID="name" runat="server" AutoPostBack="true" OnSelectedIndexChanged="name_SelectedIndexChanged">  
    <Items> 
        <telerik:RadComboBoxItem Text="Hide nested control" Value="1" Selected="true" /> 
        <telerik:RadComboBoxItem Text="Show nested control" Value="2" /> 
    </Items> 
</telerik:RadComboBox> 
                          
<asp:Panel ID="somePnl" runat="server" style="display:none;">  
    <nested:uc2 ID="UserControl2" runat="server" /> 
</asp:Panel> 
 
<telerik:RadAjaxManagerProxy ID="uc1Proxy" runat="server">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="name">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="somePnl" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
Here's the code behind file for the above user control:
using System;  
using System.Web;  
using Telerik.Web.UI;  
 
namespace WebApplication1  
{  
    public partial class WebUserControl1 : System.Web.UI.UserControl  
    {  
        protected void name_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            if (name.SelectedValue=="1")  
                somePnl.Style["display"] = "none";  
            else 
                somePnl.Style["display"] = "block";  
        }  
    }  

Here's the nested user control and code behind:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="WebApplication1.WebUserControl2" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<br /> 
This controls visibility of text box.<br /> 
<telerik:RadComboBox ID="phoneSelect" runat="server" AutoPostBack="true" onselectedindexchanged="phoneSelect_SelectedIndexChanged">  
    <Items> 
        <telerik:RadComboBoxItem Text="Show text box" Value="-1" /> 
        <telerik:RadComboBoxItem Text="" Value="" Selected="true" /> 
        <telerik:RadComboBoxItem Text="(123)555-1234" Value="(123)555-1234" /> 
    </Items> 
</telerik:RadComboBox> 
 
<asp:Panel ID="phoneNumberPnl" runat="server" style="display:none;">  
    <telerik:RadNumericTextBox ID="phoneNumber" runat="server" 
        MaxLength="20" 
        Width="160" /> 
</asp:Panel> 
 
<telerik:RadAjaxManagerProxy ID="uc2Proxy" runat="server">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="phoneSelect">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="phoneNumberPnl" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
using System;  
using System.Web;  
using System.Web.UI;  
 
namespace WebApplication1  
{  
    public partial class WebUserControl2 : System.Web.UI.UserControl  
    {  
        protected void phoneSelect_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            if (phoneSelect.SelectedValue != "-1")  
                phoneNumberPnl.Style["display"] = "none";  
            else 
                phoneNumberPnl.Style["display"] = "block";  
        }  
    }  

 

Note that I'm using ASP Panels and setting style attributes to show and hide because the actual app needs all the controls to be actually present on the form.

Am I doing something wrong or is this a bug?

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 23 Dec 2008, 12:20 PM
Hi Melies,

I tested the provided code and was able to replicate the described issue locally.
Better approach in this scenario is instead of setting display option for the problematic panel to use the Visibility property of the RadNumericTextBox. The controls that are added to the RadAjax settings should be always visible on the page. If you use this approach the presented error does not occur.
Please find attached a sample application which shows the correct work of the application.

All the best,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
PJ Melies
Top achievements
Rank 1
answered on 23 Dec 2008, 04:26 PM
Thank you for the response.  I played around with the code you provided.  It turns out my original problem was caused by me not including the triggering control as an updated control in the radAjaxManagerProxy.  Once I did that the logic of changing the display style of the panel worked as I originally intended.

I did verify that even when I set the visiblity of the RadTextBox to false the values that are on that field are still posted back to the server.  So it appears that I don't need the panel afterall (I was only including the panel because I wanted the underlying form fields to be present even when they shouldn't be displayed).

Can you verify that setting the Visibility=false property of all Telerik controls will still allow those controls values to be posted back on subsequent posts?
0
Accepted
Maria Ilieva
Telerik team
answered on 29 Dec 2008, 02:12 PM
Hi,

You are correct that seven setting the Visibility=false property to Telerik RadTextBox it will allow those control values to be posted back on subsequent posts.This is valid for all Telerik controls

All the best,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
PJ Melies
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
PJ Melies
Top achievements
Rank 1
Share this question
or