More in this section

Forums / Developing with Sitefinity / How to customize CommentsList.ascx?

How to customize CommentsList.ascx?

2 posts, 0 answered
  1. Nisha
    Nisha avatar
    17 posts
    Registered:
    17 Jun 2009
    01 Aug 2009
    Link to this post
    hi,
        I want to know how to customize CommentsList.ascx control. I am using this control in News module to show and post the comments. The  problem is when user submits the comment it saves successfully and display it on the backend's  Moduls - News -Comments sectiom, but if user hits refresh button on the browser or press F5 key on the same page, the duplicate comment gets added..
        To prevent this scenario i have code, which i want to apply that page before the comment gets submited. But i am not getting where to apply that code??
        The code with me is :
    private bool _refreshState = false;  
        protected override void LoadViewState(object savedState)  
        {  
            object[] allStates = (object[])savedState;  
            base.LoadViewState(allStates[0]);  
            _refreshState = (bool)allStates[1];  
        }  
     
        protected override object SaveViewState()  
        {  
            Session["__ISREFRESH"] = _refreshState;  
            object[] allStates = new object[2];  
            allStates[0] = base.SaveViewState();  
            allStates[1] = !_refreshState;  
            return allStates;  
        }  
     
    protected void btnSubmit_Click(object sender, EventArgs e)  
        {  
             
            if (_refreshState != (bool)Session["__ISREFRESH"])  
            {  
               //submit the comment  
            }  
              
        } 
    Please tell me how to use this code to prevent comment submition on every refresh of the page.

    Thanks and Regards,
    - Nisha
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Aug 2009
    Link to this post
    Hello Nisha,

    Thank you for using our services.

    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>

    Now you will have to make your NewsView control to use this template when displaying single news items (~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx).

    I hope that the provided information will help you. If you have more questions, please feel free to contact us.

    Kind regards,
    Rado
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
2 posts, 0 answered