Value must not be null for Controls and Behaviors

Thread is closed for posting
5 posts, 0 answers
  1. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 28 Apr 2009 Link to this post


    I'm having the weirdest problem with the RadUpload control.
    I was trying to integrate the control in a fairly complicated aspx page and got the following error from Visual Studio (9.0.etc.) when running the page in debug mode:
    "Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
    Parameter name: element"
    I tried to read up on this problem on the internet but couldn't make much sense of what is written on the subject.
    So I decided to make a test page just for this control, following the instructions in the "RadControls for ASPNET AJAX Q1 2008 Documentation" (or at least for the larger part), to see how I could get it working.

    And guess what? It worked!
    So I started experimenting with renaming the uploaded file and stuff and it still worked. Up to a certain point...
    The thing is I don't see what it was that caused a problem. To me it seems as if from one moment to the other it just stopped working.
    Although the problem was not the same error. All of the sudden "rulMediaUpload.UploadedFiles[0]" became null all the time.

    I grew tired of it yesterday so I dropped it for the day. This morning I decided to comment all lines but those with I think it was I started with when making the test page the first time, when it still worked. And now I'm stuck again with the "Value must not be null for Controls and Behaviors" error from Visual Studio...
    I really can't see what the difference is between the code as it is this morning and yesterday morning (ignoring the commented lines) except that it did work yesterday!

    This is the code in the aspx file:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadUploadTest.aspx.cs" Inherits="CMS.Views.Tests.RadUploadTest" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="" >
    <head runat="server">
        <script type="text/javascript">
          function pageLoad() {

        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <telerik:RadUpload runat="server"
                    ControlObjectsVisibility="None" MaxFileInputsCount="1" MaxFileSize="5000000"
                    TargetFolder="~\Upload\Media" ID="rulMediaUpload" />
                <!--<telerik:RadProgressManager ID="RadProgressManager1" Runat="server" />
                <telerik:RadProgressArea ID="RadProgressArea1" Runat="server" DisplayCancelButton="True" ProgressIndicators="TotalProgressPercent">
                <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" />

    And this is the code in the corresponding aspx.cs file:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;

    namespace CMS.Views.Tests
        public partial class RadUploadTest : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)

            protected void Button1_Click(object sender, EventArgs e)
                //string defaultTempFileName= Path.Combine(GetPathFromBase("Upload\\Media"),"xxx.jpg");
                //DateTime d = DateTime.Now;
                //string s = "" + d.Year + d.Month.ToString().PadLeft(2, '0') + d.Day.ToString().PadLeft(2, '0') + d.Hour.ToString().PadLeft(2, '0') + d.Minute.ToString().PadLeft(2, '0');
                //string FinalFileName= Path.Combine(GetPathFromBase("Upload\\Media"),"final-"+s+".jpg");
                //FileInfo uploadedFile = new FileInfo(defaultTempFileName);

    In both files the commented lines didn't cause any problems when not commented until... they did!

    Please help me out here.

  2. Genady Sergeev
    Genady Sergeev avatar
    1595 posts

    Posted 28 Apr 2009 Link to this post

    Hi Mink,

    The only mistake that I see with your code is that your upload button is inside an UpdatePanel and it is not added to the PostBackTriggers of the latter panel. RadUpload cannot upload files using AJAX calls. This is a limitation of the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. In order to upload a file your application must perform a full page postback. What you need to do is to add your upload button to the postback triggers of the update panel. Example:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server"
                <asp:PostBackTrigger ControlID="Button1" /> 
                <telerik:RadUpload runat="server" 
                    ControlObjectsVisibility="None" MaxFileInputsCount="1" MaxFileSize="5000000" 
                    TargetFolder="~\MyUploads" ID="rulMediaUpload" /> 
                <telerik:RadProgressManager ID="RadProgressManager1" Runat="server" /> 
                <telerik:RadProgressArea ID="RadProgressArea1" Runat="server" DisplayCancelButton="True" ProgressIndicators="TotalProgressPercent"
                <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" /> 

    Other than that, I did not manage to reproduce the error that you are receiving. I am sending you my test project ( which uses the code you have sent us ). Please give it a try and observe whether the problem persists there.

    Best wishes,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft R3 2016 release webinar banner
  4. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 28 Apr 2009 Link to this post

    Oke, great. Thanks for the help. I'll try it in a few moment, after I finish my current task.
    But I allready have a question.
    Didn't I comment the lines creating the UpdatePanel? So that in it's simplest form there isn't an UpdatePanel at all?
    Or did I forget to do that?
    But I will certainly will give your version a try. Hope it works.
    Will let you know if it did.
  5. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 29 Apr 2009 Link to this post

    It works!
    Thanks for the support.
    Although I'm still a bit puzzled about the whole UpdatePanel thing because I have tried to leave it out again and now it still worked...
    But when it works it works and I'm quite happy about it.

    By the way, I discovered that I did something else wrong as well. I forgot to alter the Web.config so that I can upload larger files. Maybe that was part of the reason I had some problems.

    And one other thing. If I understand the documentation correctly I should be able to select multiple options for the ProgressIndicators property of the RadProgressArea control in the properties window, just like for the ControlObjectsVisibility property of the RadUpload control. This doesn't work for me.
    The work around I used was to memorize the options I wanted and type them myself in the source view of the aspc page. So I definately got it working the way I wanted, but maybe you should look into it.
  6. Brian Kowald
    Brian Kowald avatar
    5 posts
    Member since:
    Aug 2009

    Posted 29 May 2014 in reply to Mink Link to this post

    This happened to us when we had a table as an ajax initiator. Removing that solved the problem. Only telerik controls should be listed as ajax initiators.
Back to Top
DevCraft R3 2016 release webinar banner