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

editing throws js null reference exception

2 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
golddog
Top achievements
Rank 1
golddog asked on 20 Oct 2011, 03:43 PM
I had this working yesterday.  I'm not sure what changed.  Clicking the edit button in one of my RadGrid rows throws out:

Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

from javascript.  Yesterday, it was bringing up the edit form just fine and letting me make changes.  It seems as if all my grid events fire on the client o.k. (Edit, ItemCommand, ItemDataBound, ItemCreated), then this error pops up.

Here's my markup if it helps.  I don't see what's going on.

(BTW, using the edit form to create an entity is working just fine.   It's only when I hit the edit link on an existing row).

Thanks,

Scott
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MediaList.ascx.cs" Inherits="PledgeWeb.MediaLibrary.Controls.MediaList" %>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        var mediaList = {};
 
        mediaList.get_AddDocumentModalUrl = function mediaList_getAddDocumentModalUrl() {
            return '<%= Page.ResolveClientUrl("~/MediaLibrary/Modals/AddDocument.aspx") %>';
        }
 
        mediaList.get_ViewDocumentModalUrl = function mediaList_getViewDocumentModalUrl(docId) {
            var url = '<%= Page.ResolveClientUrl("~/MediaLibrary/Modals/ViewDocument.aspx") %>' + '?id=' + docId;
            return url;
        }
 
        //On insert and update buttons click temporarily disables ajax to perform upload actions
        //for a more detailed description of why we need this.
        function conditionalPostback(sender, eventArgs) {
            var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
            if (eventArgs.get_eventTarget().match(theRegexp)) {
                var upload = $find(window['UploadId']);
 
                //AJAX is disabled only if file is selected for upload (i.e., new documents)
                if (upload != null && upload.getFileInputs()[0].value != "") {
                    eventArgs.set_enableAjax(false);
                }
            }
        }
 
        function validateRadUpload(source, e) {
            e.IsValid = false;
 
            var upload = $find(source.parentNode.getElementsByTagName('div')[0].id);
            var inputs = upload.getFileInputs();
            for (var i = 0; i < inputs.length; i++) {
                //check for empty string or invalid extension
                if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                    e.IsValid = true;
                    break;
                }
            }
        }
 
    </script>
</telerik:RadCodeBlock>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
        mediaList.onAddDocumentWindowClosed = function mediaList.onAddDocumentWindowClosed(sender, eventArgs) {
            var returnValue = eventArgs.get_argument();
 
            if (!Utils.WasRadWindowCancelled(returnValue, true)) {
                __doPostBack('', '');
            }
        }
 
        mediaList.openAddDocumentWindow = function mediaList_openAddDocumentWindow() {
            Utils.OpenRadWindow
                (
                    mediaList.get_AddDocumentModalUrl(),
                    600,
                    400,
                    mediaList.onAddDocumentWindowClosed
                );
        }
 
        mediaList.openViewWindow = function mediaList_openViewWindow(docId) {
            Utils.OpenRadWindow
                (
                    mediaList.get_ViewDocumentModalUrl(docId),
                    600,
                    400
                );
        }
    </script>
</telerik:RadScriptBlock>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
    <asp:Panel ID="pnlMsg" runat="server">
        <asp:Label ID="lblMsg" runat="server" Style="color: Red; font-weight: bold;" />
    </asp:Panel>
 
    <telerik:RadGrid ID="grdMediaLibrary" runat="server" Skin="Default" AutoGenerateColumns="false"
        Width="100%" AllowPaging="true" PageSize="10" OnItemDataBound="grdMediaLibrary_ItemDataBound"
        AllowAutomaticInserts="false" AllowAutomaticUpdates="false" OnEditCommand="grdMediaLibrary_Edit"
        OnUpdateCommand="grdMediaLibrary_Update" OnInsertCommand="grdMediaLibrary_Insert"
        OnItemCommand="grdMediaLibrary_ItemCommand" OnItemCreated="grdMediaLibrary_ItemCreated"
        ShowStatusBar="true">
        <PagerStyle Mode="NumericPages" AlwaysVisible="false" Position="Bottom" CssClass="Pager" />
        <MasterTableView CommandItemDisplay="Top" ClientDataKeyNames="ID" DataKeyNames="ID">
            <NoRecordsTemplate>
                <asp:Label Text="No documents to display" runat="server" /></NoRecordsTemplate>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                </telerik:GridEditCommandColumn>
                <telerik:GridTemplateColumn UniqueName="MenuColumn">
                    <ItemTemplate>
                        <telerik:RadMenu ID="itemMenu" runat="server" CausesValidation="false">
                            <Items>
                                <telerik:RadMenuItem Value="topMenuItem" ImageUrl="~/Images/collapsed_toggleExpandHover.gif"
                                    HoveredImageUrl="~/Images/collapsed_toggleExpandActive.gif" CssClass="SM_imageButton">
                                    <Items>
                                        <telerik:RadMenuItem Text="Archive" ImageUrl="~/Images/archive.jpg" />
                                        <telerik:RadMenuItem Text="Recover From Archive" ImageUrl="~/Images/undo.png" />
                                    </Items>
                                </telerik:RadMenuItem>
                            </Items>
                        </telerik:RadMenu>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="ID" Visible="false" ReadOnly="true" UniqueName="DocID" />
                <telerik:GridTemplateColumn HeaderText="Document Name" UniqueName="DocName" ReadOnly="false">
                    <ItemTemplate>
                        <asp:Label ID="lblDocName" runat="server" Text='<%#Eval("Name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadUpload ID="ruDocument" runat="server" MaxFileInputsCount="1" />
                        <asp:CustomValidator ID="cvDocument" runat="server" ClientValidationFunction="validateRadUpload"
                            ErrorMessage="Please select a file" Display="Dynamic" />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description">
                    <ItemTemplate>
                        <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="txtDescription" runat="server" Text='<%# Bind("Description") %>'
                            Columns="50" Rows="5" TextMode="MultiLine" />
                        <des:RequiredTextValidator ID="rtvDescription" runat="server" ControlIDToEvaluate="txtDescription"
                            ErrorMessage="* Required" />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Date Created" DataField="CreatedDate" ReadOnly="true"
                    DataFormatString="{0:d}" />
                <telerik:GridBoundColumn HeaderText="Operator" DataField="CreatedBy" ReadOnly="true" />
                <telerik:GridImageColumn ImageUrl="~/Images/Tick.gif" HeaderText="Archived?" UniqueName="ArchivedColumn" />
                <telerik:GridTemplateColumn ReadOnly="true" UniqueName="ViewColumn">
                    <ItemTemplate>
                        <asp:HyperLink ID="hypView" runat="server" Text="View" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn ButtonType="PushButton" />
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>
 
<telerik:RadAjaxLoadingPanel ID="loadingPanel" runat="server" Skin="Default" />
<telerik:RadAjaxManagerProxy ID="ajaxProxy" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxPanel1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdMediaLibrary" LoadingPanelID="loadingPanel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>

2 Answers, 1 is accepted

Sort by
0
golddog
Top achievements
Rank 1
answered on 21 Oct 2011, 10:41 PM
Found it.    Finally saw that I had a bit in my ItemDataBound event handler where I got the RadUpload object and tried to set MaxFileSize.

However, I did that before the null check by mistake.

On edits, I set the column whose EditTemplate includes the RadUploads to ReadOnly, since we don't need them to upload a document, just edit the information supporting it.  Of course, then in ItemDataBound the RadUpload wasn't found.

Strange to me that the ajax postback failed with the kind of message it did instead of a NullReferenceException at the point I tried to set MaxFileSize, but there you go.
0
Mira
Telerik team
answered on 25 Oct 2011, 06:33 AM
Hello Golddog,

I am glad that the issue is resolved.

However, please note that during partial page rendering, all server errors are masked as JavaScript errors by the RadAjax.
Please examine this help topic for additional information.

I hope this helps.

All the best,
Mira
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
golddog
Top achievements
Rank 1
Answers by
golddog
Top achievements
Rank 1
Mira
Telerik team
Share this question
or