网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.关于Adodb.Stream的使用说明.
.改进性能和样式的 25+ ASP 技巧(.
.避免asp的SQL的执行效率低.
.在ASP中自动创建多级文件夹的函数.
.检测整数和长整数的函数.
.好东西,翻页程序,大家可以参考.
.在Form域中Post大于100K的数据 .
.ASP实用技巧 强制刷新网页 .
.测字符串长度函数.
.带日期标注的日历控件.
.利用ASP技术实现文件直接上传功能.
.动态创建下拉菜单.
.ASP写的自动生成SELECT表单的函数.
.如何使用 Microsoft Access 和 A.
.MS IIS虚拟主机ASP源码泄露 (MS,.
.用ASP随机生成文件名的函数.
.怎样传送更多的数据在表单中.
.如何用asp进行base64加密.
.为ASP开发者介绍ColdFusion.
.一个简单的用存储过程分页.

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

发表日期:2001-3-26


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 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;
        }
    }
}



上一篇:VBSctipt 5.0中的新特性 人气:9735
下一篇:ASP.NET中的XML表单控件 人气:9520
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐