Use multiple runat=server form in asp.net

Source: Internet
Author: User
Tags visual studio
Asp.net|server asp.net does not support multiple runat=server forms on the same page, to solve this problem, you can place each form in a separate panel control so that users can simply switch between different panel through radio buttons.
The code is as follows:
2formexample.aspx

<%@ Page language= "C #" codebehind= "2FormExample.cs" autoeventwireup= "false" inherits= "_3leaf_app. C2formexample "%>
<meta Name=vs_targetschema content= "HTML 4.0" >
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
<meta name= "Code_language" content= "C #" ><body>

<form method= "POST" runat= "Server" id=form1>
<p>lookup by
<asp:radiobutton id=radiobutton1 runat= "Server" text= "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>
The 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>

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 the call are required by the asp+ Windows Form Designer.
//
InitializeComponent ();
}

<summary>
Required to Designer support-do not modify
The contents is 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 the last name";
}

public void button1_click (object sender, System.EventArgs e)
{
Label1.Text = "You want to search on the name of";
}

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.