
asp.net代码练习 work018 panel和placeholder的使用
发布日期:2021-05-06 21:17:45
浏览次数:14
分类:原创文章
本文共 2427 字,大约阅读时间需要 8 分钟。
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work018.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Panel和PlaceHolder</title></head><body> <form id="form1" runat="server"> <div> <div> <h4>Panel</h4> 性别:<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" Text="男" OnCheckedChanged="RadioButton1_CheckedChanged" GroupName="sex" /> <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="true" Text="女" OnCheckedChanged="RadioButton2_CheckedChanged" GroupName="sex" /> <asp:Panel ID="Panel1" runat="server"> 妻子姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </asp:Panel> <asp:Panel ID="Panel2" runat="server"> 丈夫姓名:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </asp:Panel> </div> <div> <h4>PlaceHolder</h4> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </div> </div> </form></body></html>
webform1.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace work018{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //panel if (!IsPostBack) { Panel1.Visible = false; Panel2.Visible = false; } //placeholder Button btn1 = new Button(); btn1.Text = "动态添加控件"; btn1.Click += btn1_Click; PlaceHolder1.Controls.Add(btn1); } void btn1_Click(object sender, EventArgs e) { Literal lit = new Literal(); lit.Text = "PlaceHolder1控件总共容纳了" + PlaceHolder1.Controls.Count + "个控件<br>"; PlaceHolder1.Controls.Add(lit); } protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { Panel1.Visible = true; Panel2.Visible = false; } protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { Panel1.Visible = false; Panel2.Visible = !Panel1.Visible; } }}
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月04日 22时35分21秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Oracle创建用户,分配表空间
2019-03-04
自定义标签(JSP2.0)简单标签
2019-03-04
MyBatis自定义类型转换器
2019-03-04
机器学习(湖北师范大学教程)-极大似然估计算法
2019-03-04
【C# 重构】—参数化查询, 需要参数,但未提供该参数
2019-03-04
决策树(二)—— ID3和C4.5
2019-03-04
MySQL~教你满分回答什么是数据库索引? 索引的数据结构是什么? 什么是事务?
2019-03-04
操作系统~进程的状态、转换、控制
2019-03-04
操作系统~线程概念以及多线程模型
2019-03-04
数据结构~缓存淘汰算法--LRU算法(Java的俩种实现方式,时间复杂度均为O(1))
2019-03-04
Python:函数 ----》装饰器函数
2019-03-04
Python:面向对象
2019-03-04
Python练习题 :随机生成一批数
2019-03-04
Spring源码:prepareBeanFactory(beanFactory);方法
2019-03-04
Spring源码:initApplicationEventMulticaster源码解析
2019-03-04
AcWing 786: 第k个数
2019-03-04
AcWing 828. 模拟栈
2019-03-04
添加Selinux权限
2019-03-04
ifconfig网络配置信息解析
2019-03-04
(2019.9.10测试可用)如何在Windows的cmd中使用ls命令
2019-03-04