Creating custom control of user profile
I'm creating a simple control of user profile as
UserProfileView.ascx
<%@ Control Language="C#" %><%@ Register Assembly="Telerik.Web.UI, Version=2011.1.413.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><%@ Register Assembly="Telerik.Sitefinity, Version=4.1.1501.0, Culture=neutral, PublicKeyToken=b28c218413bdf563" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %><sitefinity:Message runat="server" ID="message" ElementTag="div" RemoveAfter="30000" FadeDuration="10" /><asp:Label ID="Label1" Text="<%$ Resources:UserProfileResources, FullName %>" runat="server" AssociatedControlID="FullName" Font-Bold="True"/><br /><asp:TextBox ID="FirstName" runat="server" Width="100%"/><asp:RequiredFieldValidator ID="FullNameRequired" runat="server" CssClass="sfError" Display="Dynamic" ControlToValidate="FullName" SetFocusOnError="true"> <strong><asp:Literal ID="fnRequired" runat="server" Text="<%$ Resources:UserProfileResources, FullNameRequired %>"></asp:Literal></strong> </asp:RequiredFieldValidator><br /><br />using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Sitefinity.Security;using Telerik.Sitefinity.Security.Model;using Telerik.Sitefinity.Web.UI;using Telerik.Sitefinity.Localization;namespace UserProfileControl public class UserProfile : SimpleView private const string layoutTemplateName = "UserProfileControl.Resources.ControlTemplates.UserProfileView.ascx"; protected override string LayoutTemplateName get return layoutTemplateName; protected override HtmlTextWriterTag TagKey get return HtmlTextWriterTag.Div; protected virtual string FullName get return this.Container.GetControl<TextBox>("FullName", true).Text; protected Message Message get return this.Container.GetControl<Message>("message", true); protected override void OnInit(System.EventArgs e) base.OnInit(e); Res.RegisterResource<UserProfileResources>(); protected override void InitializeControls(GenericContainer container) UserManager manager = UserManager.GetManager(); this.Container.GetControl<TextBox>("FullName", true).Text = HttpContext.Current.User.Identity.Name as string; using Telerik.Sitefinity.Localization;using Telerik.Sitefinity.Localization.Data;namespace UserProfileControl [ObjectInfo("UserProfileResources", ResourceClassId = "UserProfileResources")] public class UserProfileResources : Resource [ResourceEntry("FullName", Value = "FullName")] public string FullName get return this["FullName"]; [ResourceEntry("FullNameRequired", Value = "Full name required")] public string FullNameRequired get return this["FullNameRequired"];
|
Hi Olga,
The problem seems to be caused by
UserManager manager = UserManager.GetManager();
Does removing the line fix the error? If you call this line from another control or a page, do you get errors?
Best wishes,
Ivan Dimitrov
the Telerik team
Removing the line doesn't fix error, but adding the line is cause of error at another control.
I change line
this.Container.GetControl<TextBox>("FullName", true).Text = HttpContext.Current.User.Identity.Name as string;this.Container.GetControl<TextBox>("FullName", true).Text = "Name";
|
Hello Olga,
Please use VirtualPathProvider to register the control template. Since Sitefinity 4.1 we introduced VPP
www.sitefinity.com/.../taking_advantage_of_the_virtual_path_provider_in_sitefinity_4_1.aspx
so one way is registering the template through global.asax as the post above shows.
The other way is to set a prefix in your private const string used for the template like "~/SfSamples", then this prefix should be registered in the configuration (itefinity>> Administration >> Settings >> Advanced >> VirtualPathSettings )together with the assembly where the template is defined
public override string LayoutTemplatePath
get
return layoutTemplatePath;
protected override string LayoutTemplateName
get
return null;
private const string layoutTemplatePath = "~/SfSamples/Telerik.Sitefinity.Samples1.Resources.MyCustomTemplate.ascx";
Greetings,
Ivan Dimitrov
the Telerik team
I registry VirtualPathProvider (screenshot attach) and rewrite UserProfile
namespace UserProfile public class UserProfile : SimpleView public override string LayoutTemplatePath get return layoutTemplatePath; protected override string LayoutTemplateName get return null; private const string layoutTemplatePath = "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx"; protected override HtmlTextWriterTag TagKey get return HtmlTextWriterTag.Div; protected virtual string FullName get return this.Container.GetControl<TextBox>("FullName", true).Text; protected Message Message get return this.Container.GetControl<Message>("message", true); protected override void OnInit(System.EventArgs e) base.OnInit(e); Res.RegisterResource<UserProfileResources>(); protected override void InitializeControls(GenericContainer container) this.Container.GetControl<TextBox>("FullName", true).Text = "admin";
and get error
Cannot find template "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx".
Stack Trace:
[ArgumentException: Cannot find template "~/SFUserProfile/UserProfile.Resources.ControlTemplates.UserProfileView.ascx".]
Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration, Boolean addChildrenAsDirectDescendants) +864
Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +436
Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +1056
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() +122
System.Web.UI.Control.PreRenderRecursiveInternal() +49
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6878
Where am I mistaken? Have you sample control using virtual path?
Hello Olga,
Is you template build as an embedded resource?
Kind regards,
Ivan Dimitrov
the Telerik team
Yes,sure. Template build as embedded resource