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

Value must not be null for Controls and Behaviors

4 Answers 213 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mink
Top achievements
Rank 1
Mink asked on 28 Apr 2009, 09:47 AM
Hi,

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script type="text/javascript">
    
      function pageLoad() {
      }
    
    </script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        
        <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>-->
            <telerik:RadUpload runat="server"
                AllowedFileExtensions=".jpg,.jpeg,.gif,.png,.bmp,.aac,.mp3,.wav,.wma,.asf,.avi,.mov,.mp4,.mpg,.qt,.swf,.wmv"
                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">
            </telerik:RadProgressArea>-->
                
            <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" />
        <!--</ContentTemplate>
        </asp:UpdatePanel>-->
    </div>
    </form>
</body>
</html>

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");
            //rulMediaUpload.UploadedFiles[0].SaveAs(defaultTempFileName);
            //FileInfo uploadedFile = new FileInfo(defaultTempFileName);
            //uploadedFile.MoveTo(FinalFileName);
        }
    }
}

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

Please help me out here.


4 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 28 Apr 2009, 01:25 PM
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"
        <Triggers> 
            <asp:PostBackTrigger ControlID="Button1" /> 
        </Triggers> 
        <ContentTemplate>
            <telerik:RadUpload runat="server" 
                AllowedFileExtensions=".jpg,.jpeg,.gif,.png,.bmp,.aac,.mp3,.wav,.wma,.asf,.avi,.mov,.mp4,.mpg,.qt,.swf,.wmv" 
                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"
            </telerik:RadProgressArea>                
            <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" /> 
        </ContentTemplate> 
        </asp:UpdatePanel> 

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.
0
Mink
Top achievements
Rank 1
answered on 28 Apr 2009, 01:31 PM
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.
0
Mink
Top achievements
Rank 1
answered on 29 Apr 2009, 08:21 AM
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.
0
Brian Kowald
Top achievements
Rank 1
answered on 29 May 2014, 05:45 PM
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.
Tags
Upload (Obsolete)
Asked by
Mink
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Mink
Top achievements
Rank 1
Brian Kowald
Top achievements
Rank 1
Share this question
or