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

Forums / Developing with Sitefinity / Trying to populate authorText

Trying to populate authorText

7 posts, 0 answered
  1. Randy Bauer
    Randy Bauer avatar
    67 posts
    Registered:
    25 Sep 2009
    19 Nov 2009
    Link to this post

    I am trying to populate the authorTxt box with the username and found the following code, but it gives me an error.

    ((

    TextBox)this.Container.FindControl("authorTxt")).Text = Membership.GetUser().UserName.ToString();

    The error I get is:

     'UserTemplates_ListPageDetail' does not contain a definition for 'Container' and no extension method 'Container' accepting a first argument of type 'UserTemplates_ListPageDetail' could be found (are you missing a using directive or an assembly reference?)

    How can I populate the authorTxt.Text when the page loads?

    -R

     

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    20 Nov 2009
    Link to this post
    Hello Randy Bauer,

    Thank you for using our services.

    You are trying to populate this textbox, but where in which control/control template. If you are talking about customizing the template for comments in the News View for example you have to edit the control template for the comments list. You can find CommentsList.ascx template file, both in the control templates folders for Blogs (~/Sitefinity/ControlTemplates/Blogs/), and for Generic Content (~/Sitefinity/ControlTemplates/Generic_Content/). You can copy one of those to the control templates for news and modify it. After you have edited the template for the comments list you have to "tell" your CommentsList control to use this template. Open the template for the single news item (~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx) and at the bottom find the declaration for the the CommentsList control and provide the path to your template like this:
    <div id="comments" class="sf_contentComments">  
    <sfWeb:CommentsList ID="commentsList" runat="server" CssClass="sf_commentsList"  
             LayoutTemplatePath="~/Sitefinity/ControlTemplates/News/CommentsList.ascx">   
    </sfWeb:CommentsList>  
    </div>

    Then edit the template file like this:
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Telerik.Security.UserManager userManager = new Telerik.Security.UserManager();
            MembershipUser currentUser = userManager.GetUser();
            if (currentUser != null)
            {
                ProfileBase userProfile = ProfileBase.Create(currentUser.UserName);
                this.authorTxt.Text = userProfile.GetPropertyValue("FirstName").ToString() + " " + userProfile.GetPropertyValue("LastName").ToString();
                //or
                //this.authorTxt.Text = currentUser.UserName;
                this.emailTxt.Text = currentUser.Email;
                //if you have added a profile fiedl for user website you can use
                //this.webSiteTxt.Text = userProfile.GetPropertyValue("Website").ToString();  
                //or just hardcode it
                this.webSiteTxt.Text = "http://yoursite.com";    
            }
        }
    </script>

    All you are left to do is to map the template for the News View so that it can use the edited comments list template.

    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Randy Bauer
    Randy Bauer avatar
    67 posts
    Registered:
    25 Sep 2009
    20 Nov 2009
    Link to this post
    Hi Radoslav,

    Thanks very much for your response.  I've been able to make most of this work and it's very nice.  But for some reason, the Page_Load event is not firing.  Actually, I just figured out that none of my changes are taking affect.  I added the CommensList.ascx file to my UserTemplates folder.  I believe I have it reference correctly and not sure what it is actually calling.

    OK, I just changed:

    LayoutTemplatePath

     

    ="~/UserTemplates/CommentsListx.ascx"

     


    I thought this would cause the app to fail, but it still loaded...

    Here is my code in ListPageDetail.ascx:
    <div class="sf_postComments" runat="server" id="postCommentsPlh">  
        <sfWeb:BlogCommentsList ID="commentsList" runat="server" CssClass="sf_commentsList" ValidationGroup="commentInfo" LayoutTemplatePath="~/UserTemplates/CommentsList.ascx">  
        </sfWeb:BlogCommentsList> 
    </div> 

    Here is my code for the CommentsList.ascx page:
    <%@ Control Language="C#" %> 
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %> 
    <telerik:JsFileLink id="jsLink" runat="server" ScriptType="jQuery" /> 
     
    <script type="text/C#" runat="server">  
        //protected override void  OnLoad(EventArgs e)    
        protected void Page_Load(object sender, EventArgs e)  
        {  
            Telerik.Security.UserManager userManager = new Telerik.Security.UserManager();  
            MembershipUser currentUser = userManager.GetUser();  
            if (currentUser != null)  
            {  
                ProfileBase userProfile = ProfileBase.Create(currentUser.UserName);  
                this.authorTxt.Text = userProfile.GetPropertyValue("FirstName").ToString() + " " + userProfile.GetPropertyValue("LastName").ToString();  
                //or  
                //this.authorTxt.Text = currentUser.UserName;  
                this.emailTxt.Text = currentUser.Email;  
                //if you have added a profile fiedl for user website you can use  
                //this.webSiteTxt.Text = userProfile.GetPropertyValue("Website").ToString();     
                //or just hardcode it  
                this.webSiteTxt.Text = "http://yoursite.com";       
            }  
        }  
    </script> 
     
    <asp:Repeater ID="commentsRepeater" runat="Server">  
     
    <HeaderTemplate> 
        <asp:PlaceHolder runat="server" ID="headerHolder">  
              
                <h3> 
                <asp:Literal runat="server" Text="<%$Resources:Comments %>" /> 
                  
                &nbsp;<asp:Literal ID="commentsCount" runat="Server"></asp:Literal></h3>  
              
        </asp:PlaceHolder> 
        <ol class="commentsView">  
    </HeaderTemplate> 
    <ItemTemplate> 
         <!-- comment goes here --> 
            <sfWeb:CommentItem Id="anonCommentContainer" runat="server" CssClass="anonymousComment" >   
              
             <Template> 
               <class="sf_commentAuthor">  
                    <strong> 
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink> 
                        <asp:Literal runat="Server" ID="authorName"  Visible="false"></asp:Literal>   
                    </strong> 
                    <%--<abbr class="date" id="commentDate" runat="server" > </abbr>--%> 
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" /> 
                </p> 
                <asp:Label ID="text" runat="server"></asp:Label> 
            </Template> 
             
            </sfWeb:CommentItem> 
             
            <sfWeb:CommentItem Id="authorCommentContainer" runat="server"  CssClass="authorComment">   
             <Template> 
                 <class="sf_commentAuthor">  
                    <strong> 
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink> 
                        <asp:Literal runat="Server" ID="authorName"  Visible="false" ></asp:Literal>   
                    </strong> 
                    <%--<abbr class="date" id="commentDate" runat="server"</abbr>--%> 
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" /> 
                </p> 
                <asp:Label ID="text" runat="server"></asp:Label> 
             </Template> 
              
           </sfWeb:CommentItem> 
    </ItemTemplate> 
    <FooterTemplate> 
        </ol> 
    </FooterTemplate> 
    </asp:Repeater> 
    <asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">  
        <class="commentMessage">  
            <asp:Literal runat="server" Text="<%$Resources:CommentMessageModeration %>"></asp:Literal> 
        </p> 
    </asp:PlaceHolder> 
    <div> 
        <h3><asp:Literal runat="server" Text="<%$Resources:PostComment %>"></asp:Literal></h3>  
        <fieldset> 
            <ol> 
                <li class="texarea-wrapper">  
                    <asp:Label ID="Label1" runat="Server" Text="<%$Resources:Comment %>" AssociatedControlID="commentTxt"></asp:Label> 
                     <div> 
                        <href="#" class="formattingOptionsToggleBtn" onclick='if($(this).parent().hasClass("formattingOptions")){$(this).parent().removeClass("formattingOptions");$(this).text("Formatting options");}else{$(this).parent().addClass("formattingOptions");$(this).text("Hide formatting options"); } return false;'>Formatting options</a> 
                        <telerik:RadEditor   
                                runat="server"   
                                ID="commentTxt" 
                                ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml" 
                                EnableEmbeddedSkins="True"   
                                Skin="Default"   
                                Width="100%" 
                                EditModes="Design">    
                         </telerik:RadEditor>     
                    </div>    
                     <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"   
                            ControlToValidate="commentTxt" 
                            ErrorMessage="<%$Resources:CommentEmpty %>"   
                            Display="dynamic"   
                            ValidationGroup="commentInfo" 
                            CssClass="sf_commentsValidator">  
                            <strong>Message text is required</strong> 
                     </asp:RequiredFieldValidator>                                                                                                                      
                </li>             
                <li> 
                    <asp:Label ID="Label2" runat="Server" Text="<%$Resources:Name %>" AssociatedControlID="authorTxt"></asp:Label> 
                    <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox> 
                    <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt" ErrorMessage="<%$Resources:NameEmpty %>" Display="dynamic" CssClass="commentsValidator"></asp:RequiredFieldValidator>                     
                </li> 
                <li> 
                    <asp:Label ID="Label3" runat="Server" Text="<%$Resources:Email %>" AssociatedControlID="emailTxt"></asp:Label> 
                    <asp:TextBox ID="emailTxt" runat="server" size="30"></asp:TextBox> 
                    <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="<%$Resources:InvalidEmail %>" Display="dynamic" CssClass="commentsValidator"></asp:RegularExpressionValidator> 
                </li> 
                <li> 
                    <asp:Label ID="Label4" runat="Server" Text="<%$Resources:WebSite %>" AssociatedControlID="webSiteTxt"></asp:Label> 
                    <asp:TextBox ID="webSiteTxt" runat="server" size="30"></asp:TextBox> 
                </li> 
                <li> 
                    <asp:Button ID="submitBtn" runat="server" Text="<%$Resources:PostThisComment %>" CssClass="commentsButton" /> 
                </li> 
            </ol> 
        </fieldset> 
    </div> 
     
     

    Thanks,

    Randy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Nov 2009
    Link to this post
    Hi Randy Bauer,

    You can try adding AutoEventWireup="true" or just create a code behind of the template and move the server code there. Make sure that the template is mapped to the control.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Randy Bauer
    Randy Bauer avatar
    67 posts
    Registered:
    25 Sep 2009
    20 Nov 2009
    Link to this post
    Hi Ivan,

    I added that AutoEventWireup="true" and that did nothing.  I will try moving the code, but not sure that will make a difference.  It appears to be calling some type of default template.  When I removed the LayoutTemplatePath, it still loaded a default template.

    Is there something else I need to do to make sure the template is wired to the control?  I'm thinking I may need to add something to controls configuration file, but not sure what.

    Thanks,

    Randy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Nov 2009
    Link to this post
    Hello Randy Bauer,

    Since LayoutTemplatePath property of BlogCommentsList is set, then the custom template should be used. You can make some changes to the html to see whether your template is loaded. Do the same for ListPageDetail. If ListPageDetail is not not mapped, the Page_Load also is not called.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Randy Bauer
    Randy Bauer avatar
    67 posts
    Registered:
    25 Sep 2009
    20 Nov 2009
    Link to this post

    Ivan,

    I finally got this to work and here is what I had to do.  I've been testing these combinations for the past hour.

    1)  I put the following in the Telerik.Sitefinity.Configuration.ControlsConfig.xml.



    <viewSettings hostType="Telerik.Blogs.WebControls.BlogCommentsList" layoutTemplatePath="~/UserTemplates/CommentsList.ascx" /> 



    Setting the layoutTemplatePath to the path on the ListPageDetail.ascx page did nothing. 

    2) If I was running this within VS, I had to stop the ASP.Net Development Server to have the changes take affect.

    3) If I was running this via IIS, I had to do an IISReset.

    Not sure if this is the way that this is supposed to work, but I've been testing this for over an hour and it works only if I put and entry in the xml file and restart the ASP.Net Development Server.

    -R
Register for webinar
7 posts, 0 answered