Difficulty hiding part of a form with Usercontrol

Asked

Viewed 114 times

0

I have a form called frmCadastroBens that declares a Usercontrol, which I call wucCadastroBens. In this form I register the UC like this:

<%@ 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" %>

And then like this:

<uc1:wucCadastroBens ID="wucCadastroBensNovoPV" runat="server" />
    <br />
    <uc2:wucCadastroBens ID="wucCadastroBensUsadosPV" runat="server" />
    <br />
    <asp:RadioButtonList RepeatDirection="Horizontal" ID="rdbGarantiaConfissao" runat="server" RepeatLayout="Flow" RepeatColumns="0" CellSpacing="-1">
        <asp:ListItem Text="Confissão de Dívida " Value="1"></asp:ListItem>
        <asp:ListItem Text="Garantia Adicional"  Value="2"></asp:ListItem>
    </asp:RadioButtonList>
    <uc3:wucCadastroBens ID="wucCadastroConfissaoDividaPV" runat="server" />

It turns out that I need, at the moment of clicking the Sign Up button, I hide the other UC, let me explain. It is just a UC, registered as I said above. When I am in uc1, I must show the Registration Panel and hide the others. The problem is one panel only and this method is inside wucCadastroBens.Cs and not in frmCadastroBens.cs. If I was inside frmCadastroBens.Cs, I would do so: wucCadastroBensUsadosPV.Visible = false; This would work, but I happen to be inside wuc and can no longer have "3" "panels", for example, as I have in frmCadastrBens. Then comes the question: How can I do, so that when registering a new one, I hide the other panels (one for each wuc registered in frmCadastroBens). At the moment when the page is loaded, the three panels appear.

1 answer

1


Try to do the following: In frmCadastroBens.Cs add a public method that changes the visibility of Usercontrol.

public void setUCVisible(wucCadastroBens userControl) { ... }

So inside the Usercontrol, do the following:

var parent = this.Parent.Page as frmCadastroBens;
parent.setUCVisible(this);
  • Giving this error: Object Reference not set to an instance of an Object.

  • I forgot to access the Parent Control Page property.

  • Any error here is new ground for me. I will test and already put.

Browser other questions tagged

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