小弟在最近看到有人這樣寫..就把它分享出來...
小弟在最近看到有人這樣寫..就把它分享出來...
asp.net(c#)
ControlCnt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlCnt.aspx.cs" Inherits="ControlCnt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:Panel>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:Panel>
</div>
</form>
</body>
</html>
ControlCnt.aspx.cs


















protected void showControl(Control controls)





if (ctl.HasControls())






執行結果: