当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP.NET中使用多个runat=server form

ASP
在ASP程序中实现数据库事务控制
怎样开始一个ASP网站的设计
ASP中使用ServerVariables集合详解
关于解决商务平台ASP程序的源代码泄漏设想与思考
ASP通用模板类
javascript利用xmlhttp获得服务器时钟的方法
asp+oracle分页程序类(XDOWNPAGE2.0)
ASP中实现小偷程序的原理和简单
asp中vbscript访问xml文件
ASP防SQL注入攻击程序
用ASP读INI配置文件的函数
asp实现关键词获取(各搜索引擎,gb2312及utf-8)
xmlhttp组件获取远程文件并筛选出目标数据
XMLHTTP Get HTML页面时的中文乱码之完全客户端Script解决方案
WEB打印设置解决方案一(通过修改注册表改变IE打印设置)
WEB打印设置解决方案二(利用ScriptX.cab控件改变IE打印设置)
WEB打印设置解决方案三(FileSystem组件实现WEB打印)
WEB打印设置解决方案四(在ASP中实现网络打印功能)
ASP实用技巧 强制刷新网页
Access通用-自动替换数据库中的字符串

ASP.NET中使用多个runat=server form


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 56 ::
收藏到网摘: n/a

  ASP.NET 在同一个页面不支持多个 runat=server forms,要解决这个问题,可以把每个 form 放在一个单独的 panel 控件中,这样用户就可以简单地通过单选按钮在不同 panel 间切换。
代码如下:
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