转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
*Using the ASP.NET Panel Control...         ★★★★

*Using the ASP.NET Panel Control...

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1877 更新时间:2009/4/23 10:45:00

By: John Kilgo Date: March 6, 2003 Download the code. Printer Friendly Version

The Panel Control is so easy to use that I hesitated to even write an article about it. But I have received several questions about it so decided to write the article anyway. The Panel Control is a container that allows you to include other server controls on it. It is primarily used for containing labels, textboxes, checkboxes and other controls that you would normally use on a web form. Panels come in handy especially when you have very large forms that become unweildy to deal with. Using panels you can reveal your form one logical section at a time and make it appear less cumbersome. The control has only a few properties, visible being the most useful.

In this example we will use three panels to display our form, along with three button controls to control the visibility of each panel. Our form actually is not very large, but it should serve the purpose of showing what can be done with the panel.

As can be seen in the following .aspx file each section contains a panel opening tag with some properties being set, followed by the server controls to be contained on the panel, followed by the panel''''s closing tag. All other processing takes place in a code-behind file to be shown further below. At the top of the aspx file are several buttons which will be used to show the various panels. Notice that the three buttons that control the panels raise and OnCommand event which will be handled in the code-behind file. I also place a Submit button on the form although I wrote no code for it.

<%@ Page Language="vb" Src="PanelControl.aspx.vb" Inherits="PanelControl" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>PanelControl</title>
<meta content="Microsoft Visual Studio.NET 7.0" name=GENERATOR>
<meta content="Visual Basic 7.0" name=CODE_LANGUAGE>
<meta content=JavaScript name=vs_defaultClientScript>
<meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
</head>
<body MS_POSITIONING="GridLayout">
<form id=Form1 method=post runat="server">
<asp:Button ID="btnName" CommandName="name" OnCommand="button_click" text="Name" Runat="server" />
<asp:Button ID="btnAddress" CommandName="address" OnCommand="button_click" Text="Address" Runat="server" />
<asp:Button ID="btnPhone" CommandName="phone" OnCommand="button_click" Text="Telephone" Runat="server" />
<asp:Button ID="btnSubmit" Text="Submit" Runat="server" />
<asp:Panel id="pnlName"
        style="Z-INDEX: 101; LEFT: 20px; POSITION: absolute; TOP: 64px"
        runat="server"
        Height="182px"
        Width="278px">
  <TABLE>
    <TR>
      <TD><asp:Label id="lblFirstName" Runat="server" text="First Name:"></asp:Label></TD>
      <TD><asp:TextBox id="txtFirstName" Runat="server"></asp:TextBox></TD></TR>
    <TR>
      <TD><asp:Label id="lblMiddleName" Runat="server" text="Middle Name:"></asp:Label></TD>
      <TD><asp:TextBox id="txtMiddleName" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblLastName" Runat="server" text="Last Name:"></asp:Label></TD>
      <TD><asp:TextBox id="txtLastName" Runat="server"></asp:TextBox></TD>
    </TR>
  </TABLE>
</asp:Panel>
<asp:Panel id="pnlPhone"
        style="Z-INDEX: 102; LEFT: 20px; POSITION: absolute; TOP: 64px"
        runat="server"
        Height="182px"
        Width="278px">
  <TABLE>
    <TR>
      <TD><asp:Label id="lblPhone" Runat="server" text="Telephone:"></asp:Label></TD>
      <TD><asp:TextBox id="txtPhone" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblCellPhone" Runat="server" text="Cell Phone:"></asp:Label></TD>
      <TD><asp:TextBox id="txtCellPhone" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblFax" Runat="server" text="FAX:"></asp:Label></TD>
      <TD><asp:TextBox id="txtFax" Runat="server"></asp:TextBox></TD>
    </TR>
  </TABLE>
</asp:Panel>
<asp:Panel id="pnlAddress"
        style="Z-INDEX: 103; LEFT: 20px; POSITION: absolute; TOP: 64px"
        runat="server"
        Height="182px"
        Width="278px">>
  <TABLE>
    <TR>
      <TD><asp:Label id="lblAddr1" Runat="server" text="Address1:"></asp:Label></TD>
      <TD><asp:TextBox id="txtAddr1" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblAddr2" Runat="server" text="Address2:"></asp:Label></TD>
      <TD><asp:TextBox id="txtAddr2" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblCity" Runat="server" text="Cityh:"></asp:Label></TD>
      <TD><asp:TextBox id="txtCity" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblState" Runat="server" text="State:"></asp:Label></TD>
      <TD><asp:TextBox id="txtState" Runat="server"></asp:TextBox></TD>
    </TR>
    <TR>
      <TD><asp:Label id="lblZipCode" Runat="server" text="Zip Code:"></asp:Label></TD>
      <TD><asp:TextBox id="txtZipCode" Runat="server"></asp:TextBox></TD>
    </TR>
  </TABLE>
</asp:Panel>
</FORM>
</body>
</html>

It is in the code-behind file, shown below that we control the visibility of the three panels we defined in the aspx file. Depending on which button was clicked we set its corresponding panel''''s visibility to "True" and the other panels'''' visibility to false.

Public Class PanelControl : Inherits System.Web.UI.Page
  Protected WithEvents pnlName As System.Web.UI.WebControls.Panel
  Protected WithEvents pnlAddress As System.Web.UI.WebControls.Panel
  Protected WithEvents lblFirstName As System.Web.UI.WebControls.Label
  Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblMiddleName As System.Web.UI.WebControls.Label
  Protected WithEvents txtMiddleName As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblLastName As System.Web.UI.WebControls.Label
  Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblAddr1 As System.Web.UI.WebControls.Label
  Protected WithEvents txtAddr1 As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblAddr2 As System.Web.UI.WebControls.Label
  Protected WithEvents txtAddr2 As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblCity As System.Web.UI.WebControls.Label
  Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox
  Protected WithEvents lblState As

[1] [2]  下一页


[C语言系列]将MDI子窗体置于父窗体中的panel之上  [系统软件]The GRETA Regular Expression Template Archive
[系统软件]OLE with the internet explorer  [常用软件]Firefox: What’s the next step?
[VB.NET程序]The UDPChat Source(VB.NET)  [Delphi程序]The Delphi Object Model (PART III)
[Delphi程序]The Delphi Object Model (PART II)  [Delphi程序]The Delphi Object Model (PART I)
[Delphi程序]Five of the best tools for Delphi  [Delphi程序]2004.11.28.Tour of the IDE
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台