Accessing an Embedded Resource UserControl from a Embedded R

Posted by Community Admin on 05-Aug-2018 10:39

Accessing an Embedded Resource UserControl from a Embedded Resource Usercontrol??

All Replies

Posted by Community Admin on 04-Jan-2011 00:00

I have a Usercontrol that inherits from SimpleView that has a RadGrid control in it. The RadGrid uses a UserControl as an edit Form. How can I load the control into the RadGrid EditFormSettings?

I also am trying to use embedded user controls with other controls such as RadWindow. Below is the LocationManager class that manages the Primary page as a user control.

[RequireScriptManager]
    public class LocationManager : SimpleView
    
 
        protected override void InitializeControls(GenericContainer container)
        
            LocationsGrid.NeedDataSource += LocationsGrid_NeedDataSource;
            LocationsGrid.InsertCommand += LocationsGrid_InsertCommand;
            LocationsGrid.UpdateCommand += LocationsGrid_UpdateCommand;
            //LocationsGrid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
            ////LocationsGrid.MasterTableView.EditFormSettings.UserControlName = "BranchManagementModule.Resources.EditLocation.ascx";
            //LocationsGrid.MasterTableView.EditFormSettings.EditColumn.ButtonType = GridButtonColumnType.LinkButton;
            //LocationsGrid.MasterTableView.EditFormSettings.EditColumn.UniqueName = "editColumn1";
            //LocationsGrid.MasterTableView.EditFormSettings.EditColumn.InsertText = "Add a new location";
        
 
        void LocationsGrid_UpdateCommand(object sender, GridCommandEventArgs e)
        
 
        
 
        void LocationsGrid_InsertCommand(object sender, GridCommandEventArgs e)
        
            var item = (GridEditableItem)e.Item;
            var userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            var db = new RegionalDataContext();
 
            var location = new BranchLocation
                               
                                   BranchLocationId = Guid.NewGuid(),
                                   BranchLocationName = (userControl.FindControl("txtLocationName") as TextBox).Text,
                                   AddressInfo = (userControl.FindControl("txtAddressInfo") as TextBox).Text
                               ;
 
            if (new Guid((userControl.FindControl("ddlRegionalOffice") as RadComboBox).SelectedValue) == Guid.Empty)
            
                var region = new Region RegionId = Guid.NewGuid(), RegionName = location.BranchLocationName ;
                location.RegionId = region.RegionId;
 
                db.Regions.InsertOnSubmit(region);
            
            else
            
                location.RegionId = new Guid((userControl.FindControl("ddlRegionalOffice") as RadComboBox).SelectedValue);
            
 
            db.BranchLocations.InsertOnSubmit(location);
            db.SubmitChanges();
 
            e.Canceled = false;
        
 
        void LocationsGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        
            var module = new BranchManagementModule();
            LocationsGrid.DataSource = module.GetLocationsAsQueryable();
        
 
        protected override string LayoutTemplateName
        
            get return "BranchManagementModule.Resources.LocationManagerView.ascx";
        
 
        protected virtual RadGrid LocationsGrid
        
            get
            
                return Container.GetControl<RadGrid>("RadGrid1", true);
            
        
 
 
    

Below is the main page as a user control that is embedded as a resource.

<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Backend"
    TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ControlDesign" %>
<div class="sfWrapper">
    <h1 class="sfBreadCrumb">
        Regional Offices Manager</h1>
    <span class="sfBreadCrumbForward"><a href="Regions">Manage Regions</a></span>
    <span class="sfBreadCrumbForward"><a href="Managers">Manage Regional Managers</a></span>
    <div class="sfMain sfClearfix">
        <div class="sfContent">
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Sitefinity" />
            <telerik:RadAjaxPanel ID="radAjaxPanel1" Width="100%" Height="100%" runat="server"
                LoadingPanelID="RadAjaxLoadingPanel1" HorizontalAlign="NotSet">
                <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="false"
                    ShowStatusBar="True" Skin="Sitefinity" ShowFooter="True">
                    <MasterTableView commanditemdisplay="Top" datakeynames="BranchLocationId">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" AddNewRecordText="Add Prinipal Profile">
                        </CommandItemSettings>
                        <CommandItemTemplate>
                            <asp:LinkButton ID="lnkAddNewProfile" runat="server" Font-Bold="true" CausesValidation="false"
                                CommandName="InitInsert" Text="Add a new location" />
                        </CommandItemTemplate>
                        <Columns>
                            <telerik:GridBoundColumn DataField="BranchLocationId" HeaderText="Location Id" ReadOnly="True"
                                SortExpression="BranchLocationId" UniqueName="BranchLocationId" DataType="System.Guid"
                                Visible="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Region.RegionId" HeaderText="Region Id" ReadOnly="True"
                                SortExpression="Region.RegionId" UniqueName="RegionId" DataType="System.Guid"
                                Visible="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="BranchLocationName" HeaderText="Location Name"
                                ReadOnly="True" SortExpression="Location Name" UniqueName="BranchLocationName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="AddressInfo" HeaderText="Location Address" ReadOnly="True"
                                SortExpression="Office Location" UniqueName="AddressInfo">
                            </telerik:GridBoundColumn>
                            <telerik:GridEditCommandColumn HeaderText="Edit Location" EditText="Edit this Location">
                            </telerik:GridEditCommandColumn>
                        </Columns>
                        <EditFormSettings UserControlName="BranchManagementModule.Resources.EditLocation.ascx" EditFormType="WebUserControl">
                            <EditColumn UniqueName="editCommandColumn1" InsertText="Add a new Location" />
                        </EditFormSettings>
                    </MasterTableView>
                </telerik:RadGrid>
            </telerik:RadAjaxPanel>
        </div>
    </div>
</div>

I have wrapped the Edit user control also Below is the code for these.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Web.UI;
using Telerik.Web.UI;
 
namespace BranchManagementModule.Modules
    public class EditLocationControl: SimpleView
    
        private object _dataItem = null;
 
        protected object DataItem
        
            get
            
                return this._dataItem;
            
            set
            
                this._dataItem = value;
            
        
 
        protected override void InitializeControls(GenericContainer container)
        
            DataBinding += new EventHandler(EditLocationControlModule_DataBinding);
        
 
        void EditLocationControlModule_DataBinding(object sender, EventArgs e)
        
            var db = new RegionalDataContext();
            var noRegion = new RadComboBoxItem("None - [Creates new Region]", Guid.Empty.ToString());
            DdlRegionalOffice.Items.Add(noRegion);
            foreach (Region region in db.Regions.OrderBy(s => s.RegionName))
            
                var regionItem = new RadComboBoxItem(region.RegionName,
                                                     region.RegionId.ToString());
                try
                
                    if (DataBinder.Eval(DataItem, "Region.RegionId") != null &&
                        new Guid(DataBinder.Eval(DataItem, "Region.RegionId").ToString()) == region.RegionId)
                        regionItem.Selected = true;
                
                catch (Exception ex)
                
                
 
                DdlRegionalOffice.Items.Add(regionItem);
            
        
 
        protected override string LayoutTemplateName
        
            get return "BranchManagementModule.Resources.EditLocationControlView.ascx";
        
 
        protected virtual TextBox TxtLocationName
        
            get
            
                return Container.GetControl<TextBox>("txtLocationName", true);
            
        
 
        protected virtual TextBox TxtAddressInfo
        
            get
            
                return Container.GetControl<TextBox>("txtAddressInfo", true);
            
        
 
        protected virtual RadComboBox DdlRegionalOffice
        
            get
            
                return Container.GetControl<RadComboBox>("ddlRegionalOffice", true);
            
        
 
    
 
<%@ Control Language="C#" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" %>
<%@ Import Namespace="Telerik.Web.UI" %>
<style type="text/css">
    .style1
    
        width: 100%;
    
    .style2
    
        color: #800000;
        font-family: Arial, Helvetica, sans-serif;
        font-size: xx-small;
    
    .style3
    
        font-family: Arial, Helvetica, sans-serif;
        font-size: small;
        color: #800000;
    
</style>
<table class="style1">
    <tr>
        <td colspan="3" align="left">
            <span class="style3"><strong>If this is a stand alone location, Choose None from the Region drop-down. This will create a blank region using this locations name. A office must belong to a region, as the region contains the information that is displayed in the public site.</strong></span>
        </td>
    </tr>
    <tr>
        <td>
            <strong>Office Location:<br />
                <asp:TextBox ID="txtLocationName" Text='<%# DataBinder.Eval(DataItem, "BranchLocationName") %>'
                    Width="250px" MaxLength="100" runat="server"></asp:TextBox>
            </strong>
        </td>
        <td>
            <strong>Office Address:  <span class="style2">(for locations map)</span><br />
            </strong>
            <asp:TextBox ID="txtAddressInfo" Text='<%# DataBinder.Eval(DataItem, "AddressInfo") %>'
                Width="250px" MaxLength="100" runat="server"></asp:TextBox>
        </td>
        <td>
            <strong>Belongs to Region: <span class="style2">(Region is required.)</span><br />
                <telerik:RadComboBox ID="ddlRegionalOffice" runat="server">
                </telerik:RadComboBox>
            </strong>
        </td>
    </tr>
    <tr>
        <td colspan="3" align="right">
            <asp:Button ID="btnUpdate" Text="Update" runat="server" CommandName="Update" Visible='<%# !(DataItem is GridInsertionObject) %>'>
            </asp:Button>
            <asp:Button ID="btnInsert" Text="Insert" runat="server" CommandName="PerformInsert"
                Visible='<%# DataItem is GridInsertionObject %>'></asp:Button>
              
            <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                CommandName="Cancel"></asp:Button>
        </td>
    </tr>
</table>

Any help is appreciated and Is urgently needed!!

Thanks,

John Tolar

Posted by Community Admin on 04-Jan-2011 00:00

Digging Further I have found EmbeddedTemplateAttribute but I am not sure how it works as it doesn't do anything when used as an attribute on the LayoutTemplatePath override 

any help??

Posted by Community Admin on 18-Jan-2011 00:00

Hi John Tolar,

 First, I want to apologise for the delay.

There is a difference between user controls and custom controls, and you could not have possibly created a user control that inherits from SimpleView, because it doesn't inherit UserControl. It is very important to understand the difference.

The RadGrid documentation states that you cannot load an edit form from an embedded template; it can be loaded as inner template (declaratively) or as user control

RadWindow can be used as a controls container. It is an iframe, and as such, can open urls and embed them within your page. The effect you are referring to can be achieved if you had a page and pass it as the NavigateUrl of your dialog. The behaviour could be controlled with querystring parameters.

Kind regards,
Dido
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This thread is closed