Exception when adding usercontrol more than once

Asked

Viewed 178 times

1

Hello. I have a user control newsletter and it is added in various places within the project, for each page on which it is called, a property is set to insert the email into a particular group of emails (GrupoEmailNewsletter). It turns out that now beyond the internal pages the same UC will be on MasterPage, where he started giving problems.

In the master is registered and called:

<%@ Register Src="../UserControl/BoxNewsletter.ascx" TagName="BoxNewsletter" TagPrefix="uc3" %>
<uc3:BoxNewsletter ID="boxNewsletter" runat="server" GrupoEmailNewsletter="Geral" />

And on the page GrupoA.aspx is also registered and called:

<%@ Register TagPrefix="uc5" Src="~/Include/UserControl/BoxNewsletter.ascx"  TagName="Newsletter" %>
<uc5:Newsletter id="ucNewsletter" runat="server" GrupoEmailNewsletter="GrupoA" />

When to access the page GrupoA.aspx, the following error occurs:

ERRO DO SISTEMA:
Exceção do tipo 'System.Web.HttpUnhandledException' foi acionada.
Uma exceção foi acionada pelo destino de uma chamada.
Já existe uma entrada com a mesma chave.

I have located the ids and have no equal. What else would this error?

  • It can be an id of your Usercontrol it will be duplicated if you use it on Masterpage and then use it on another page you inherit from Masterpage.

  • 1

    @Thank you, that’s exactly it. In this User Control Newsletter has validations, in this Master were not added to the RequeredFieldValidator. I added the property ClientIDMode="AutoID" in all the RequeredFieldValidator of UC and worked properly.

  • Okay, you can post how you did it as an answer, so others who have the same problem will know how to solve it.

1 answer

0


The UserControl newsletter I developed has validations. I use the RequiredFieldValidator to check if the field is empty. The pages they inherit from MasterPage has the name modified, the validation components of the UserControl did not have the name modified, in this case I added the property ClientIDMode="AutoID" in the components RequiredFieldValidator to change the id.

 <asp:RequiredFieldValidator ID="rfvNomeNewsletter" runat="server" Display="None"
    ErrorMessage="Informe seu nome." ControlToValidate="txtNomeNewsletter" SetFocusOnError="true"
    ValidationGroup="vgrNewsletter" ClientIDMode="AutoID"></asp:RequiredFieldValidator>

Thus, the id of the element that is on the page inherited from the master page is: ctl00_cphMasterPortal_ucBoxNewsletter_rfvNomeNewsletter
The element that is on the masterpage: ctl00_boxNewsletter_rfvNomeNewsletter
Not causing duplicate ID error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.