Doubt about using multiple user controls on the same page

0

The most difficult thing here is to ask the right question to not get downvote, but come on. I will try to explain well, because the doubt is complex or boring. I will ask specific questions to avoid questions with multiple answers. Here it goes. I have 3 user control, but my application only uses one and I need the others. I went to see the code of the main form and the colleague registered the same uc 3 times. See part of the code as it was.

Page Title="" Language="C#" MasterPageFile="~/Core.Master" AutoEventWireup="true" MaintainScrollPositionOnPostback="true" CodeBehind="frmCadastroBens.aspx.cs" Inherits="Scania.SOMC.Web.frmCadastroBens" %>
<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc1" %>
<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc2" %>
<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="css/cadastroBens.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!-- INICIO - Campos Hidden para controle -->
    <asp:HiddenField ID="hdfCdProcesso" runat="server" Value="0" />
    <asp:HiddenField ID="hdfSomenteLeitura" runat="server" />
    <asp:HiddenField ID="hdfNmUsuario" runat="server" />
    <asp:HiddenField ID="hdfCdUsuario" runat="server" />
    <asp:HiddenField ID="hdfAdministrador" runat="server" />
    <asp:HiddenField ID="hdfCdTipoProcesso" runat="server" />
    <asp:HiddenField ID="hdfWucChamador" runat="server" />
    <asp:HiddenField ID="hdfPreencheDocumentoCadFornecedor" runat="server" />
    <!-- FIM - Campos Hidden para controle -->

    <h2>Bens em aquisição / garantia</h2>    
    <br />
    <uc1:wucCadastroBens ID="wucCadastroBensNovoPV" runat="server" />
    <br />
    <uc2:wucCadastroBens ID="wucCadastroBensUsadosPV" runat="server" />
    <br />
    <uc3:wucCadastroBens ID="wucCadastroConfissaoDividaPV" runat="server" />
    <br />

In this way I can not, for example, use wucBensUsados, only wucBensNovos. The question is: Should I also register the wucBensUsados? Is this the correct procedure?

    
asked by anonymous 06.01.2015 / 18:13

1 answer

2

Yes, in order to use the page you must register the control.

It has an easier way of doing this than going from page to page, just register in web.config, for example

configuration>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="uc1" src="WUC/wucCadastroBens.ascx" tagName="wucCadastroBens"/>
      </controls>
    </pages>
  </system.web>

And in your case, you registered the same user control 3 times, I believe that is the problem.

<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc1" %>
<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc2" %>
<%@ Register src="WUC/wucCadastroBens.ascx" tagname="wucCadastroBens" tagprefix="uc3" %>
    
06.01.2015 / 18:32