+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Can't use Bind in RadGrid FormTemplate in custom control

Can't use Bind in RadGrid FormTemplate in custom control

8 posts, 1 answered
  1. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    15 Feb 2011
    Link to this post
    Hello
    I have a custom control that is using a RadGrid that uses a Linqdatasouce to one of our external databases. I'm trying to use a EditTemplate, but any control within that template that uses a <%# %> expression causes the error below:
    This occurs in textboxes with a

    Text='<%# Bind("Id") %>'

    It occurs in buttons from the RadGrid examples page as below:
    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>

    The error:
    System.ArgumentNullException: Value cannot be null.
    Parameter name: expression

    [ArgumentNullException: Value cannot be null.
    Parameter name: expression]
       System.Web.UI.DataBinder.Eval(Object container, String expression) +8705859
       System.Web.UI.DataBinder.Eval(Object container, String expression, String format) +12
       Telerik.Sitefinity.Web.UI.Templates.Attribute.GetValue(SubstitutionItem subst, Control bindingContainer) +515
       Telerik.Sitefinity.Web.UI.Templates.Attribute.GetValue(PropertyDescriptor descriptor, Control bindingContainer) +53
       Telerik.Sitefinity.Web.UI.Templates.Attribute.SetAttribute(Object component, Control bindingContainer, Boolean bound) +167
       Telerik.Sitefinity.Web.UI.Templates.BoundAttribute.bindingContainer_DataBinding(Object sender, EventArgs e) +20
       System.Web.UI.Control.OnDataBinding(EventArgs e) +91
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +201
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +201
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +201
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
       System.Web.UI.Control.DataBind() +15
       Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +238
       Telerik.Web.UI.GridTableView.CreateInsertItem(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ControlCollection rows) +320
       Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1118
       Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +652
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
       Telerik.Web.UI.GridTableView.PerformSelect() +16
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
       Telerik.Web.UI.GridTableView.DataBind() +256
       Telerik.Web.UI.GridTableView.Rebind() +49
       Telerik.Web.UI.GridTableView.InsertItem(IDictionary newValues) +147
       Telerik.Web.UI.GridTableView.InsertItem() +15
       Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +3089
       Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +137
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +38
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +87
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

    Using the autogenerated edittemplate works without generating an error but we want to use a custom template.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Feb 2011
    Link to this post
    Hi Ryan,

    If you use our template parser for your control it is not possible to use expression like this one shown in your code

    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>

    I suggest that you should try using VirtualPath provider implementation that we made for the official release of Sitefinity 4.0. To use it, you should override LayoutTemplatePath property in your control in case it inherits from SimpleView. Note that the path should start with ""~/sfres/": Below is a sample code

    public override string LayoutTemplatePath
    {
        get
        {
            return "~/sfres/Telerik.Sitefinity.Resources.Templates.Backend.MyGrid.ascx";
        }
     
        set
        {
            base.LayoutTemplatePath = value;
        }
    }

    Let me know how it goes.

    All the best,
    Ivan Dimitrov
    the Telerik team
  3. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    17 Feb 2011
    Link to this post
    Is there any further documentation/examples of this anywhere because I've added an override for LayoutTemplatePath and it can't find the template. I've searched through the SDK examples and How to's and can't find anything. The template is an embedded resource, is this incorrect?
  4. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    18 Feb 2011
    Link to this post
    Hi Ivan

    I still can't get this to work. Is the ascx control still meant to be an embedded resource, and if not, where does it need to be placed in order to be found?

    Thanks

    Ryan

    [ArgumentException: Cannot find template "/SFRes/Test.Resources.Views.TestView.ascx".]
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration) +850
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +446
       Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +790
       Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +119
       Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +21
       Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +46
       System.Web.UI.Control.EnsureChildControls() +102
       System.Web.UI.Control.PreRenderRecursiveInternal() +42
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Feb 2011
    Link to this post
    Hi Ryan,

    When you use Virtual Path provider the template should be embedded, but you should configure some settings from Sitefinity >> Administration >> Settings >> Advanced >> VirtualPathSettings >> Virtual Paths. You need to set   - path to the template and - namespace and assembly name of your class library.

    If you do not use embedded resource the template could be added to a folder of your application and it should be processes by ASP.NET parser.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Answered
  6. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    21 Feb 2011
    Link to this post
    I can't access the VirtualPathSettings node, it seems to get stuck in a loop on both IE and Firefox. Just says "loading".
    I've tried adding a VirtualPathSettingsConfig.config into the Configuration directory, but that hasn't helped either.
  7. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    21 Feb 2011
    Link to this post
    Thanks Ivan,

    I got the custom module working with LayoutTemplatePath now by manually editing the VirtualPathSettingsConfig.config.

    Is there a way of programmatically adding this setting during the module installation?

    (the issue remains in the backend that i can not access the VirtualPath settings as it is stuck in a loop but it's not preventing me from continuing for the moment)

    Ryan
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Feb 2011
    Link to this post
    Hello Ryan,

    I remember that there was a bug with the way that the node is expanded, but it should be fixed in our internal builds.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
8 posts, 1 answered