上一篇:用ASP.NET动态生成图像(转2) >>
在 ASP.NET 中使用多个 runat=server form
代码如下:
2FormExample.aspx
<%@ Page language="c#" Codebehind="2FormExample.cs" AutoEventWireup="false" Inherits="_3leaf_app.C2FormExample" %>
<html><head>
<meta name=vs_targetSchema content="HTML 4.0">
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#"></head>
<body>
<form method="post" runat="server" ID=Form1>
<p>Lookup by
<asp:RadioButton id=RadioButton1 runat="server" Text="First Name" AutoPostBack="True" groupname=g1 checked=True></asp:RadioButton>
<asp:RadioButton id=RadioButton2 runat="server" Text="Last Name" AutoPostBack="True" groupname=g1></asp:RadioButton></p>
<p></p>
<p>
<asp:Panel id=Panel1 runat="server" visible=True>
First Name :
<asp:TextBox id=TextBox1 runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Button id=Button1 runat="server" Text="Submit"></asp:Button>
</asp:Panel>
<asp:Panel id=Panel2 runat="server" visible=False>
Last Name :
<asp:TextBox id=TextBox2 runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
<asp:Button id=Button2 runat="server" Text="Submit"></asp:Button>
</asp:Panel>
<p></p>
<p>
<asp:label id=Label1 runat="server"></asp:label>
</p>
</form>
</body></html>
2FormExample.cs
namespace _3leaf_app
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for C2FormExample.
/// </summary>
public class C2FormExample : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.RadioButton RadioButton2;
protected System.Web.UI.WebControls.RadioButton RadioButton1;
public C2FormExample()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer.
//
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
RadioButton1.CheckedChanged += new System.EventHandler (this.RadioButton1_CheckedChanged);
Button1.Click += new System.EventHandler (this.Button1_Click);
RadioButton2.CheckedChanged += new System.EventHandler (this.RadioButton2_CheckedChanged);
Button2.Click += new System.EventHandler (this.Button2_Click);
this.Load += new System.EventHandler (this.Page_Load);
}
public void Button2_Click (object sender, System.EventArgs e)
{
Label1.Text = "You want to search on last name";
}
public void Button1_Click (object sender, System.EventArgs e)
{
Label1.Text = "You want to search on first name";
}
public void RadioButton2_CheckedChanged (object sender, System.EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
}
public void RadioButton1_CheckedChanged (object sender, System.EventArgs e)
{
Panel1.Visible = true;
Panel2.Visible = false;
}
}
}
下一篇:ASP.NET实现HTTP方式获取功能 >>
相关文章:
- · ASP+全新接触(2) {转}
- · 用asp.net写的论坛程序
- · forum.aspx 论坛主页
- · reply.aspx 浏览贴子内容及回复
- · postmessage.aspx 上贴保存
- · .net的几个重要问题
- · 解决问题的方法:(JspFuns与开心的对话录)
- · 控件发布:带日期标注的日历控件。
- · 续上文:由于16K的限制,只能再接一节了。
- · 为什么我在中文win2000+sp1上装的vs.net不能创建各种web application,而英...
- · ASP.NET中密码保护,MD5和SHA1算法的使用
- · ASP。NET连SQL7接口源代码?
- · 我对.Net技术中asp.net应用的一点看法
- · 从一个舆论调查的制作谈面向对象的编程思路(一)
- · 从一个舆论调查的制作谈面向对象的编程思路(二)
- · 从一个舆论调查的制作谈面向对象的编程思路(三)
- · 从一个舆论调查的制作谈面向对象的编程思路(五)
- · 在asp.net中使用组件,也包括import和asemble的区别
- · 从一个舆论调查的制作谈面向对象的编程思路(四)
- · 分别用DataGrid、Repeater、DataList绑定XML数据的例子
- · 用DataList 控制元件开发的一个简单的留言本程序:
- · .Net边学边讲(二)
- · .Net边学边讲(一)
- · 里面是对一个body的属性进行server的一些设定,不过可以衍生到其他的一些htmlcontrol新手看看,或者有点...
- · 一个实现自定义event的文章。。。我还没有完全摸透。。不知道有没人有兴趣。。新手就不用看了,先学会走...
- · Server.Transfer,Response.Redirect 和 Page.Navigate 的区别
- · ASP.NET发送ICQ消息DIY
- · web页面用水晶报表的例子
- · Creating Custom Portal Modules
- · 几个.net的重要问题
- · SQL命令中DateTime格式参考
- · 关于webcontrol和pagelet的一点看法
- · 关于.net的几个重要问题的bigeagle版本
- · 关于datagrid的使用以及动态修改,以及使用存储过程的介绍
- · 转阿土伯推荐的文章:在 VS.NET 中编写 Web 应用程序(附图)(推荐)
- · 转新技术网:在ASP.NET中使用.NET组件
- · 自己写的一个资料验证的asp.net程序,大家看看吧!
- · 关于在ASP.NET 中进行调试的方法(转载自itpeople),不过我个人对第三招不以为然,有了vs.net还要那个...
