Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:34:00+00:00 2026-06-08T11:34:00+00:00

In a page when we will click the component Presentation tab we can see

  • 0

In a page when we will click the component Presentation tab we can see the component and template listed there.On clicking of Insert button just below that, it will open another window “Insert component presentation” there also we will have Insert and close button.So now what i need to do While inserting i need to check whether the combination of selected Component and Template is already present there on page or not. If yes then it should prevent inserting the same with a popup like “this combination is already present, select other componet”.
Any idea how can i proceed. How can i trigger a Javascript on the Insert button?

EDIT:

When i am subscrbing it to Page i am getting erro.My code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.ContentManagement;
using System.IO;
using System.Windows.Forms;




namespace MyEventHandlers
{
[TcmExtension("MyEventHandlerExtension")]

public class MyEventHandler : TcmExtension 
{
    public MyEventHandler()
{
  Subscribe();
}

public void Subscribe()
{
    EventSystem.Subscribe<Page, SaveEventArgs>(SaveBtnInitiated, EventPhases.Initiated);

}

private void SaveBtnInitiated(Page subject, SaveEventArgs args, EventPhases phase)
{

    try
    {
        List<string> allcplist = new List<string>();
        List<string> allcplist = new List<string>();
        foreach (ComponentPresentation cp in subject.ComponentPresentations)
        {
            allcplist.Add(cp.Component.Id + "," + cp.ComponentTemplate.Id);   
        }
        List<string> uniquecplist = allcplist.Distinct().ToList();
        if (allcplist.Count != uniquecplist.Count)
        {
            subject.Checkin(false);
            throw new Exception("Page has duplicate component presentation");

    }
    catch(Exception)
    {

    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:34:01+00:00Added an answer on June 8, 2026 at 11:34 am

    Why are you subscribing to the Component? I think it should be the Page. Then you can walk through the ComponentPresentations property.

    Code to go through the Component Presentations and throw an exception when duplicate presentations are found:

    foreach (var cpA in subject.ComponentPresentations)
    {
        if (subject.ComponentPresentations.Where(cpB => ComponentPresentationsAreEqual(cpA, cpB)).ToList().Count() > 2)
        {
            throw new DuplicateComponentPresentationsEmbeddedOnPageException();
        }
    }
    

    And the function to include cpB in the list when it is equal to cpA:

    function ComponentPresentationsAreEqual(ComponentPresentation cpA, ComponentPresentation cpB)
    {
        return cpA.Component.Id == cpB.Component.Id && cpA.ComponentTemplate.Id == cpB.ComponentTemplate.Id;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway that I can make it so the page will automatically scroll
I am loading content into a page with ajax that will have live click
User click on a link button and it will direct them to a url
I need a javascript bookmarklet that will click the Yes button on a facebook
Refer to my code below, when user click on en button, the content will
I will build a dashboard system for my apps, where a page will have
I need to write a module that gives me a page will all possible
I need help with one ajax function This is raw page setup. Page will
I have a page that will basically be used to concatenate a bunch of
I have a page that will have a full size product image and 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.