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

Forums / General Discussions / change blog post comments email to be required field

change blog post comments email to be required field

10 posts, 0 answered
  1. vipul patel
    vipul patel avatar
    37 posts
    Registered:
    12 Mar 2010
    06 Aug 2010
    Link to this post
    Hi,

    I am have tried making changes to ListPageDetail.ascx to make blog post comment a required field.  The code has validation for RegularExpressionValidator and i want to use both validations, so i add another RequiredFieldValidator for the emailTxt input field but it does not work.

    Can someone help me to get this working?

    Vipul Patel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Aug 2010
    Link to this post
    Hello vipul patel,

    Add the following validators to your template

    <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:RequiredFieldValidator runat="server" ID="RequiredVal" ControlToValidate="emailTxt"
                           ErrorMessage="email is required" Display="dynamic"
                           CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
                              
                              
                           <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt"  SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="<%$Resources:InvalidEmail %>" ValidationGroup="commentInfo"
                           Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
               </li>

    Create a custom control that inherits from BlogCommentsList and override InitializeControls as shown below

    namespace Telerik.Samples
    {
        public class BlogCommentsListCustom : BlogCommentsList
        {
            public BlogCommentsListCustom()
            {
       
            }
            /// <summary>
            /// sets the path to the template that the control will use
            /// </summary>
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/CommentsList.ascx";
                }
       
            }
       
            /// <summary>
            /// here the base logic goes
            /// </summary>
            /// <param name="controlContainer"></param>
            protected override void InitializeControls(Control controlContainer)
            {
                //base.InitializeControls(controlContainer);
                if (this.Page == null)
                {
                    Control radEditor = this.Container.GetControl<RadEditor>(TraverseMethod.BreadthFirst);
                    radEditor.Visible = false;
                }
       
                   
       
                this.dataSource = this.Manager.GetComments(this.ParentID, true, this.SortBy);
                this.Content = this.Manager.GetContent(this.ParentID);
       
                if (this.dataSource.Count > 0 && this.Visible)
                {
                    this.CommentsRepeater.DataSource = this.dataSource;
                    this.CommentsRepeater.ItemDataBound += this.CommentsRepeater_ItemDataBound;
                    this.CommentsRepeater.Visible = true;
                    this.CommentsRepeater.DataBind();
                }
                else
                    this.CommentsRepeater.Visible = false;
       
                this.SubmitButton.Command += this.SubmitButton_Command;
       
                if (this.Page != null)
                    this.Page.MaintainScrollPositionOnPostBack = true;
       
                string valGroup = string.IsNullOrEmpty(ValidationGroup) ? "commentInfo" : ValidationGroup;
                if (this.ContentVal != null)
                    this.ContentVal.ValidationGroup = valGroup;
                this.AuthorVal.ValidationGroup = valGroup;
                if (this.EmailVal != null)
                    this.EmailVal.ValidationGroup = valGroup;
                if (this.RequiredVal != null)
                    this.RequiredVal.ValidationGroup = valGroup;
                this.SubmitButton.ValidationGroup = valGroup;
                if (this.SpamProtector != null)
                {
                  // spam protector is disabled 
                }
            }
       
           protected void SubmitButton_Command(object sender, CommandEventArgs e)
            {
       
               base.SubmitButton_Command(sender, e);
       
            }
       
            protected virtual BaseValidator RequiredVal
            {
                get { return base.Container.GetControl<BaseValidator>("RequiredVal", false); }
            }
       
    }

    You have to replace the default BlogCommentsList in the ListPageDetail template you use

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. vipul patel
    vipul patel avatar
    37 posts
    Registered:
    12 Mar 2010
    09 Aug 2010
    Link to this post
    Hi Ivan,

    Thanks for your reply,

    I still cannot make it work.

    What i have done is created a custom user control with name CommentsList.ascx and code file for it CommentsList.ascx.cs.  Then i have copied the template of CommentList.ascx(from external templates) to CommentsList.ascx and the code you sent to CommentsList.ascx.cs. Then i have added the additional required field validator tag as you have mentioned in CommentsList.ascx. I have then added the required field validator tag to my ListPageDetail.ascx also. But it is still not working for me.  Can you help me where i am going wrong?
    If you could let me know which templates to edit it will help me.

    Thanks,

    Vipul Patel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Aug 2010
    Link to this post
    Hello vipul patel,

    The template you have to modify is ListPageDetail.ascx for BlogPosts control. Inside this template you should replace the default BlogCommentsList control which is declaratively added with the custom control that I have wrote.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Vipul
    Vipul avatar
    4 posts
    Registered:
    06 Aug 2010
    09 Aug 2010
    Link to this post
    Hi Ivan,

    While creating the custom control i am getting error for this.dataSource as below:

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

    I have added references to all the dll's from my website bin folder.
    Can you help me with which reference am i missing?

    Vipul
  6. Vipul
    Vipul avatar
    4 posts
    Registered:
    06 Aug 2010
    10 Aug 2010
    Link to this post
    Hi Ivan,

    Can you reply to my previous question? I cannot get your code working.

    Thanks,

    Vipul Patel
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Aug 2010
    Link to this post
    Hello Vipul,

    Define dataSource as  private IList dataSource; object in BlogCommentsListCustom class after the control references.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Vipul
    Vipul avatar
    4 posts
    Registered:
    06 Aug 2010
    11 Aug 2010
    Link to this post
    Hi Ivan,

    I am now getting null reference error as below:

    Stack Trace: 
      
      
    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Cms.Engine.WebControls.CommentsList.CommentsRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e) +87
       System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +108
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +136
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +323
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
       System.Web.UI.WebControls.Repeater.DataBind() +75
       Telerik.Samples.BlogCommentsListCustom.InitializeControls(Control controlContainer) +620
       Telerik.Cms.Web.UI.SimpleControl.CreateChildControls() +55
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
      
      
    Can you help me in resolving this error?

    Vipul
  9. Vipul
    Vipul avatar
    4 posts
    Registered:
    06 Aug 2010
    12 Aug 2010
    Link to this post
    Hi Ivan,

    Can you help me with this error?

    Vipul Patel
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Aug 2010
    Link to this post
    Hi Vipul,

    Modify BlogCommentsListCustom class as shown below

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Blogs.WebControls;
    using System.Web.UI;
    using System.Collections;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Framework.Web;
     
    /// <summary>
    /// Summary description for BlogCommentsListCustom
    /// </summary>
    namespace Telerik.Samples
    {
        public class BlogCommentsListCustom : BlogCommentsList
        {
            public BlogCommentsListCustom()
            {
     
            }
            /// <summary>
            /// sets the path to the template that the control will use
            /// </summary>
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/CommentsList.ascx";
                }
            }
     
     
            protected override void InitializeControls(Control controlContainer)
            {
                base.InitializeControls(controlContainer);
     
                this.SubmitButton.Command += this.SubmitButton_Command;
                if (this.Page != null)
                    this.Page.MaintainScrollPositionOnPostBack = true;
                string valGroup = string.IsNullOrEmpty(ValidationGroup) ? "commentInfo" : ValidationGroup;
                if (this.ContentVal != null)
                    this.ContentVal.ValidationGroup = valGroup;
                this.AuthorVal.ValidationGroup = valGroup;
                if (this.EmailVal != null)
                    this.EmailVal.ValidationGroup = valGroup;
                if (this.RequiredVal != null)
                    this.RequiredVal.ValidationGroup = valGroup;
                this.SubmitButton.ValidationGroup = valGroup;
                if (this.SpamProtector != null)
                {
     
                }
            }
     
            protected void SubmitButton_Command(object sender, CommandEventArgs e)
            {
                base.SubmitButton_Command(sender, e);
            }
     
            protected virtual BaseValidator RequiredVal
            {
                get { return base.Container.GetControl<BaseValidator>("RequiredVal", false); }
            }
           
        }
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
10 posts, 0 answered