More in this section

Forums / General Discussions / How do I require EMAIL for comments?

How do I require EMAIL for comments?

3 posts, 0 answered
  1. Marko
    Marko avatar
    148 posts
    30 Jul 2008
    18 Dec 2009
    Link to this post
    I'm using a custom template for "detail" display for my blogs, and I added this the RequiredFieldValidator for email, but it doesn't seem to work:
    <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="emailVal2" ControlToValidate="emailTxt" ErrorMessage="<%$Resources:EmailEmpty %>" Display="dynamic" CssClass="sf_commentsValidator"></asp:RequiredFieldValidator> 

    This seems to run the client javascript validation fine, but that only works if I type something into the email textbox, then delete it, then change focus into another field (I get a note that Email cannot be blank) .  But that doesn't prevent me from actually submitting the form.  And if I don't type anything into the email box when I start filling out the comment, I won't even get the client-side validation note.

    Looking at how this is done for the Author field...
    <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="sf_commentsValidator"></asp:RequiredFieldValidator> 

    ... i can't figure out what else I'm missing?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    19 Dec 2009
    Link to this post
    Hello Marko,

    The required field validator should have the same validation group as the submit button. Since the child controls of the Sitefinity Comments control are actually a controls added to the controls collection in the blog post view you will have to do this with a little bit of code. Please add this server script to the external template for viewing single blog posts, then map the template:
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
            RequiredFieldValidator emailVal2 = (RequiredFieldValidator)this.commentsList.Controls[0].FindControl("emailVal2");
            Button submitBtn = (Button)this.commentsList.Controls[0].FindControl("submitBtn");
            if (submitBtn != null && emailVal2 != null)
                emailVal2.ValidationGroup = submitBtn.ValidationGroup;       

    This should do the trick.

    All the best,
    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. Marko
    Marko avatar
    148 posts
    30 Jul 2008
    21 Dec 2009
    Link to this post
    Thanks.  That worked great!
Register for webinar
3 posts, 0 answered