0

以前は、メインユーザーコントロールを含むデフォルトのaspxページがあります。

メインのユーザーコントロールは、メニュー項目を動的にロードするためのユーザーです。たとえば、担当者販売注文

ユーザーが担当者をクリックすると、担当のコンテンツが他のサブユーザーコントロールから読み込まれます。

ここに画像の説明を入力してください

デフォルトのaspxフロントエンド

Here is the aspx page which include the main user control
     <div class="rightColumnModule2">
                                <asp:Panel ID="pnUserControl" runat="server">
                                        <uc2:SubMenuItem ID="MainMenuItem1" runat="server"/>
                                </asp:Panel>
                            </div>

submenuitemバックエンドコード

   //dynamic load other content of user control
  //I am using placeholder to load from other user control
        private void loadUserControl()
        {
            if (this.hfSelectSubItemURL.Value != "")
            {
                UserControl ucSimpleControl = LoadControl(this.hfSelectSubItemURL.Value) as UserControl;
                PlaceHolder1.Controls.Add(ucSimpleControl);
            }
        }

ContactPersonList.ascxフロントエンド

div class="rightColumnModule2">


                            <div class="rightColumnModule2TitleContainer">
                                <table class="rightColumnModule2Table">

                                    <tr>
                                        <td>
                                            <div class="rightColumnModule2Title">
                                                Contact Person</div>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                           <cc1:cusAcesslevelBtn ID="btncAdd" runat="server" aclType="Add" 
                                                CssClass="inputButonS" onclick="btncAdd_Click" Text="Add" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <!-- end of rightColumnModule2TitleContainer -->
                            <div id="Div2" class="rightColumnModule2Content" runat="server">


                                            <div class="rightColumnModule2ContentSub">
                                    <div class="rightColumnModule2TitleSub">
                                        System Information 

                                        </div>

                                        <table class="table100">
                                        <tr>
                                            <td class="tableVT" style="width: 49%">
                                                <table class="table100">
                                                    <tr>
                                                        <td class="rightColumnModule2DetailLabel" style="width: 30%">
                                                            Create by &nbsp; </td><td class="rightColumnModule2DetailColon" style="width: 5%">
                                                            : </td><td class="rightColumnModule2DetailValue" style="width: 65%">
                                                            <asp:LinkButton ID="LinkButton1" runat="server" 
                                                               ></asp:LinkButton>&nbsp;<asp:Label
                                                                ID="Label3" runat="server"></asp:Label></td></tr></table></td><td class="gapHori1" style="width: 2%">
                                            </td>
                                            <td class="tableVT" style="width: 49%">
                                                <table class="table100">
                                                    <tr>
                                                        <td class="rightColumnModule2DetailLabel" style="width: 30%">
                                                            Modify By </td><td class="rightColumnModule2DetailColon" style="width: 5%">
                                                            : </td><td class="rightColumnModule2DetailValue" style="width: 65%">
                                                            <asp:LinkButton ID="LinkButton2" runat="server"></asp:LinkButton>&nbsp;<asp:Label
                                                                ID="Label4" runat="server"></asp:Label></td></tr></table></td></tr></table>

                                                                </div>
                            </div>
                          </div>  <!-- end of rightColumnModule2Content -->

デフォルトのaspxページのContactPersonList.ascxにある[追加]ボタンを呼び出すにはどうすればよいですか?解決策を教えてください。ありがとう

4

1 に答える 1

0

あなたは2つのアプローチを持つことができます:

  1. FindControlプロパティを使用:

     Button btn1 =UserControlID.FindControl("btn1") as Button;
     if(btn1 != null)
     {
       //your stuff with button
     }
    

    また

  2. UserControl ボタンのクリック イベントを直接呼び出すことができます。

    ユーザー コントロール ページ:

    <asp:Button ID="btnClick" runat="server" Text="Button1" onclick="btn_Click" />
    

    コードビハインド:

    public event EventHandler ButtonClick;
    protected void btn_Click(object sender, EventArgs e)
    {
      ButtonClick(sender, e);
    }
    

    Aspx ページ:

    <UC1:UC1 ID="UserControl1" runat="server" />
    

    コードビハインド:

    protected void Page_Load(object sender, EventArgs e)
    {
       UserControl1.ButtonClick += new EventHandler(UserControl1_ButtonClick);
    }
    
    protected void UserControl1_ButtonClick(object sender, EventArgs e)
    {
       Response.Write("this is usercontrol button event.");
    }
    
于 2012-05-08T05:42:12.200 に答える