【问题标题】:c# Panel subpanel and buttonc# Panel子面板和按钮
【发布时间】:2013-05-03 07:23:28
【问题描述】:

我创建了一些用户控件来轻松复制标准按钮和 2 个不同的面板

假设:

The panel 1: p1 
       button B
The panel 2: p2 
       button B

一旦我的表单创建完成,p1 中有一个 B,P2 中有一个 B,如上所示。 B如果在p1需要一个动作,如果他在p2需要另一个动作

有谁知道 B 是否可以理解他是在 p1 还是 p2 ?

我已经实例化了 p1 和 p2 但这并没有真正改变他是否抓住了他是否在面板内的事实。

【问题讨论】:

  • 让我澄清几点 1.您使用的是网络用户控件?2.)这个用户控件只包含一个按钮控件?。
  • 我在这里有点困惑。如何在 2 个不同的面板中拥有相同的按钮?您可以粘贴您的代码的 sn-p 吗?

标签: c# .net button panel


【解决方案1】:

希望这对你有用。暂时我在用户控件中使用单个按钮控件:

ASCX 文件:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="buttonl.ascx.cs"Inherits="Controls_buttonl" %>
 <asp:Button ID="Button1" runat="server" Text="Button user control" 
onclick="Button1_Click" />

ASCX.cs 文件:

 protected void Button1_Click(object sender, EventArgs e)
{
    if (this.ID == "buttonl1")
    {
        //perform action according to panel1
    }
    else if (this.ID == "buttonl2")
    {
        //perform action according to panel2
    }
}

ASPX 页面(父页面):

 <form id="form1" runat="server">
<div>


    <asp:Panel ID="Panel1" runat="server" Height="99px" Width="224px">
     <uc1:buttonl ID="buttonl1" runat="server" />
    </asp:Panel>
</div>
<div>
<asp:Panel ID="Panel2" runat="server" Height="97px" Width="222px">
    <uc1:buttonl ID="buttonl2" runat="server" />
</asp:Panel>
</div>
</form>

如果仍然无法达到您的目标,请告诉我。

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    相关资源
    最近更新 更多