Exception Value cannot be null - Parameter name: virtualPath

0 Answers 494 Views
Button UI for ASP.NET AJAX in ASP.NET MVC
Gregory
Top achievements
Rank 1
Gregory asked on 16 Jun 2021, 02:42 PM

Hello,

For my RadGrid, I need 2 different ways to insert.

So, I declare I want to use User controls,

<EditFormSettings EditFormType="WebUserControl"></EditFormSettings>

and I change programmatically the form to use.

protected void rgrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddF"))
        {
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "../UserControl/UC_PDGInsertionF.ascx";
            e.Item.OwnerTableView.InsertItem();

        }
        else if (e.CommandName.Equals("AddN"))
        {
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "../UserControl/UC_PDGInsertionN.ascx";
            e.Item.OwnerTableView.InsertItem();
        }
    }

My Command buttons that show the forms work perfectly.

However, my Command buttons don't work on my User controls (both of them).


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UC_PDGInsertionN.ascx.cs" Inherits="UC_PDGInsertionN" %>
<table>
<%-- some code --%>
    <%-- Buttons --%>
    <tr> 
        <td align="right" colspan="2">
            <asp:Button ID="btnAdd" Text="Cancel" runat="server" CausesValidation="False"
                        CommandName="Add" Visible="True"></asp:Button>
            <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                        CommandName="Cancel" Visible="True"></asp:Button>
        </td>
    </tr>
</table>

Whether I click on one or the other, I get this exception:

La valeur ne peut pas être null.
Nom du paramètre : virtualPath

Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.

Détails de l'exception: System.ArgumentNullException: La valeur ne peut pas être null.
Nom du paramètre : virtualPath

[ArgumentNullException: La valeur ne peut pas être null.

Nom du paramètre : virtualPath]

   System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options) +511

   Telerik.Web.UI.GridEditFormItem.InitializeUserControlForm(GridColumn[] columns, ControlCollection controls, GridEditFormSettings formSettings) +92

   Telerik.Web.UI.GridEditFormItem.InitializeEditForm(GridColumn[] columns) +6349

   Telerik.Web.UI.GridEditFormInsertItem.InitializeEditForm(GridColumn[] columns) +37

   Telerik.Web.UI.GridEditFormItem.Initialize(GridColumn[] columns) +369

   Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +266

   Telerik.Web.UI.GridTableView.CreateInsertItem(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ControlCollection rows) +656

   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +3191

   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +1308

   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +97

   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +207

   Telerik.Web.UI.GridTableView.PerformSelect() +23

   Telerik.Web.UI.GridTableView.DataBind() +360

   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3113

   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +150

   System.Web.UI.Control.LoadRecursive() +154

   System.Web.UI.Control.LoadRecursive() +251

   System.Web.UI.Control.LoadRecursive() +251

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4082

I had to disable AJAX in the RadAjaxManager to be able to see the exception. 

Do you any idea of the source of the problem?

Doncho
Telerik team
commented on 21 Jun 2021, 08:32 AM

Thank you for the provided information, Gregory!

Based on the stack trace, it seems that there is no UserControlName set to Grid's EditFormSettings at the time of Initiating the Insert command. A possible cause for the issue could be if the InitInsert command (see Command Reference) is fired by a button or code different than the ones with CommandName(s) AddN or AddF, like clicking on the built-in Add New Record button, for instance.
Could you please share the complete markup declaration of the RadGrid along with the relevant code-behind code so we can have a better overview and assist more accurately?

No answers yet. Maybe you can help?

Tags
Button UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Gregory
Top achievements
Rank 1
Share this question
or