A.Goutam
A.Goutam

Reputation: 3494

How to find UserControl on aspx page

same as title i have add control on my aspx

<%@ Register Src="Controls/EditProduct.ascx" TagName="EditProduct" TagPrefix="uc1" %>

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ManageProduct.aspx.cs" Inherits="SAP.NET.UI.Web.Master.Product.ManageProduct" %>

<%@ Register Src="Controls/EditProduct.ascx" TagName="EditProduct" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc:OkMessageBox ID="ec" runat="server" />
    <div class="breadcrumbs">
        <ul>
            <li><a href="#">Home</a> <i class="icon-angle-right"></i></li>
            <li><a href="ManageProduct.aspx">Manage Product</a> </li>
        </ul>
    </div>
    <div class="boxed no-padding col-lg-6 col-md-6 col-sm-12 col-xs-12">
        <div class="inner">

            <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="GridView1" />
                    <asp:PostBackTrigger ControlID="imagAddNew" />
                    <asp:AsyncPostBackTrigger ControlID="EditProduct1" />
                     <asp:PostBackTrigger ControlID="ImageButton1" />

                </Triggers>
                <ContentTemplate>
        <asp:Panel ID="pnl_grid" Style="width: 100%; overflow: auto;" runat="server">
      </asp:Panel>
                    <asp:Panel ID="pnlAddEdit" runat="server" Visible="false">
     //// I want to find the below control on my code 
                        <uc1:EditProduct ID="EditProduct1" runat="server" />
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>

How to find the UserControl EditProduct1 by code on same page CS file. I try below Code to find the control

    //MasterPage _master = (MasterPage)
    //Panel _aspPanel = (Panel)this.FindControl("pnlAddEdit");
   //UserControl _userControl = (UserControl)this.FindControl("EditProduct1");
   //FormView ProductsFormView = (FormView)_userControl.FindControl("EditProduct1");
   //FindAllTextBoxes(ProductsFormView);
     ContentPlaceHolder mpContentPlaceHolder;
     mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
     // UserControl _ctrl = (UserControl)mpContentPlaceHolder.FindControl("EditProduct1");
     UserControl _uc1 = (UserControl)this.Page.FindControl("EditProduct1");

Upvotes: 0

Views: 9244

Answers (2)

Amol
Amol

Reputation: 1461

Try This remove Visible="false"

Panel a = (Panel)pnlAddEdit;
UserControl ab = (UserControl )a.FindControl("EditProduct1");

Upvotes: 1

Alexander
Alexander

Reputation: 2477

The UpdatePanel has a ContentTemplateContainer property. This container has a Controls collection. Inside that collection you will find your EditProduct.

Upvotes: 0

Related Questions