Doubt about the use of multiple user control on the same page

Asked

Viewed 526 times

0

The most difficult thing here is to ask the question the right way not to get downvote, but come on. I will try to explain it well, because doubt is complex or boring. I will ask punctual questions to avoid questions with multiple answers. There you go. I have 3 user control, but my application only uses one accurate ee of 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 />

This way I cannot, for example, use wucBensUsados, only wucBensNovos. The question is: Should I also register wucBensUsados? This is the correct procedure?

  • Take a look at my response update.

1 answer

2

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

There’s an easier way to do this than going page to page, just register on the 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’s 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" %>
  • My problem is with the other uc. I have a wucBensUsados, which I registered in frmCadastroBens.aspx and I can’t work with it. In that wuc I have a Hiddenfield that I can’t assign value to it. It gives error as if it didn’t exist. And for that reason I cannot attribute anything to any field in my wucBensUsados, only in wucBensNovos.

  • At least I didn’t see you register this UC on the page that put the code here.

  • Excuse me, this is what it looks like in the original. I made a record by removing the second record and replacing it with the new uc and it didn’t work.

Browser other questions tagged

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