如何在aspx页面上找到用户控件

时间:2014-09-19 10:17:34

标签: asp.net c#-4.0 user-controls

与标题相同我在我的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>

如何通过同一页面CS文件上的代码查找UserControl EditProduct1。我尝试下面的代码来找到控件

    //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");

2 个答案:

答案 0 :(得分:1)

尝试此删除Visible =&#34; false&#34;

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

答案 1 :(得分:0)

UpdatePanel具有ContentTemplateContainer属性。此容器具有Controls集合。在该系列中,您会找到EditProduct