日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當前位置:雨林木風下載站 > 技術開發教程 > 詳細頁面

ASP.NET中運用多個runat=server form

ASP.NET中運用多個runat=server form

更新時間:2022-05-13 文章作者:未知 信息來源:網絡 閱讀次數:

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



溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

主站蜘蛛池模板: 天天爽夜夜操 | 一区二区免费视频 | 欧美人与z0z0xxxx| 性欧美暴力猛交69hd | 亚洲精品免费观看 | 久久国产精品99久久久久久牛牛 | 欧美二级黄色片 | 欧美日性 | xxxx在线播放 | 久久亚洲午夜牛牛影视 | 国产精品一区二区四区 | 站长推荐精品午夜免费影院 | 久久免费观看国产精品 | 国产肉丝在线 | 久久乐精品 | 91精品一区二区三区在线 | 六月丁香在线播放 | 欧美乱一级在线观看 | 天天噜噜色 | 2020天天狠天天透天干天天怕 | 亚洲视频免费在线看 | 另类国产精品一区二区 | 亚洲欧美日韩精品久久亚洲区色播 | 久久成人免费网站 | xxx性欧美人| 国产精品99一区二区三区 | 亚洲成人免费在线观看 | 99久久精品久久久久久清纯 | 性盈盈影院免费视频观看在线一区 | 色婷婷综合久久久久中文一区二区 | 国内精自品线一区91 | 天天操天天干天天操 | 成人福利视频在线观看网 | 国产精品毛片天天看片 | 国产99久9在线视频 国产99久久 | 国产精品久久一区二区三区 | 日韩成人免费在线视频 | 一区二区三区四区精品 | 国产日韩91| 国产三级小视频在线观看 | 日本人成午夜免费视频 |