Answered by:
ONe webpage two user controls - Why not working as expected

Question
-
User-909867351 posted
Hi
Please can you watch the youtube video at https://youtu.be/YkgdkOIPp_4 to see my problem?
I have one page named lixo as follow:
lixo.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lixo.aspx.cs" Inherits="lixo" %> <%@ Register Src="~/carrinho1.ascx" TagPrefix="uc1" TagName="carrinho" %> <%@ Register Src="~/cabecalho1.ascx" TagPrefix="uc1" TagName="cabecalho" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"/> </head> <body> <form id="form1" runat="server"> <div> <uc1:cabecalho runat="server" ID="cabecalho1" /> <uc1:carrinho runat="server" ID="carrinho1" /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="mostra" /> </div> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> </form> </body> </html>
lixo.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class lixo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void mostra(object sender, EventArgs e) { Label portes = (Label)carrinho1.FindControl("lblLopes"); portes.Text = "------------lopes----------------"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop4477", "mostraCarrinho1();", true); } }
and usercontrol cabecalho1.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="cabecalho1.ascx.cs" Inherits="cabecalho_cabecalho" %> <%@ Register Src="~/carrinho1.ascx" TagPrefix="uc1" TagName="carrinho" %> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script type="text/javascript"> function promoDiaria1() { $('#promoDia1').modal('show'); } </script> <script type="text/javascript"> function openNatal() { $('#promoNatal').modal('show'); } </script> <uc1:carrinho runat="server" ID="carrinho1" /> <!-- topo--> <div class="row d-none d-md-block"> <nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top "> <div class="col-md-6"> <a href="#"><span class="icon-twitter"> </span></a> <a href="#"><span class="icon-facebook"></span></a> <a href="#"><span class="icon-youtube"></span></a> <a href="#"><span class="icon-tumblr"></span></a> </div> <div class="col-md-6 text-right"> <a class="active" href="default.aspx"><span class="icon-home"></span>Home</a> | <asp:LinkButton ID="LinkButton2" runat="server" >Presente Natal</asp:LinkButton> | <asp:LinkButton ID="LinkButton1" runat="server" >Promo do Dia</asp:LinkButton> | <a href="/amostras/amostras-site.aspx"><span class="icon-edit"></span>Amostras </a> | <a href="#"><span class="icon-envelope"></span>Contate-nos</a> | <span class="icon-shopping-cart"></span> <asp:LinkButton ID="LinkItemsCarro" runat="server" OnClick="Mostra_Carro" ><i class="fas fa-cart-arrow-down"></i></asp:LinkButton> | </div> </nav> </div> <!-- fim do topo --> <!--linha dois --> <div class="container d-none d-md-block"> <div class="row "> <div class="col-md-1 mt-5 "> <img src="../imagens_site/cheirabem.png" class="img-fluid" /> </div> <div class="col-md-9 mt-5 "> <div class="dotmark"> <p>Portes grátis para <b>Continente, Açores e Madeira</b>. Envios por transportadora ou correio registado. Recebe em sua casa em 24/48 horas</p> </div> </div> <div class="col-md-2 mt-5 "> <i class="fas fa-mobile-alt"></i> +351 91 945 59 01 </div> </div> </div> <!-- linha dois --> <!--fim barra pesquisa --> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
and cabecalho1.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class cabecalho_cabecalho : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void Mostra_Carro(object sender, EventArgs e) { Label portes = (Label)carrinho1.FindControl("lblLopes"); portes.Text = "------------Car Shopping-------------"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop449", "mostraCarrinho1();", true); } }
another usercontrol carrinho.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="carrinho1.ascx.cs" Inherits="carrinho" %> <script type="text/javascript"> function dadosCliente() { $('#mostraDadosCliente').modal('show'); } </script> <script type="text/javascript"> function mostraCarrinho1() { $('#mostraCarrinho').modal('show'); } </script> <%--Modal Mostra carrinho--%> <div class="modal fade modal-lg" style="left: 20%;" id="mostraCarrinho" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabelNatal"> </h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <div class="row justify-content-center"> <div class="col-md-12 col-xs-10 col-lg-11"> <asp:Label ID="lblLopes" runat="server" Text="Label"></asp:Label> </div> </div> </div> </div> </div> </div> <%--fim da modal mostra carrinho--%>
and carrinho.ascx.cs
using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Net; using System.Net.Mail; using System.Text; using System.Web; using System.Web.Configuration; using System.Web.UI; using System.Web.UI.WebControls; public partial class carrinho : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } }
As I show on movie the result of my program depends the position of
<uc1:cabecalho runat="server" ID="cabecalho1" /> <uc1:carrinho runat="server" ID="carrinho1" />
in lixo.aspx
What is wrong?
Thank you
Monday, December 3, 2018 4:56 PM
Answers
-
User-909867351 posted
Found it
I have to refer one control inside other control
from lixo.aspx
<uc1:cabecalho runat="server" ID="cabecalho1" />
Now from lixo.ascx
Control subControl = cabecalho1.FindControl("carrinho1"); Label portes = (Label)subControl.FindControl("lblLopes"); portes.Text = "------------lopes----------------"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop4477", "mostraCarrinho1();", true);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 3, 2018 5:30 PM