Multi form in one page

Posted on 2005-05-02
Last Modified: 2010-04-07
I would like to know how can I add more then 1 form on the same page. I need to have a quick search, and a login form.
but when I add both, I get an error saying that I cannot have more then one form.
Question by:Ennio
    LVL 9

    Accepted Solution

    You can't have more than one Form in ASP.NET applications (one of the many changes from ASP 3).  But this doesn't mean you can't do what you're asking.

    Attach an event handler to your "search" and "login" button's click events.

    private void Page_Load(object sender, System.EventArgs e)
          this.btnSearch.Click += new EventHandler(btnSearch_Click);
          this.btnLogin.Click += new EventHandler(btnLogin_Click);

    private void btnSearch_Click(object sender, EventArgs e)
          // Code to handle search here

    private void btnLogin_Click(object sender, EventArgs e)
          // Code to handle login here
    LVL 1

    Author Comment

    Ok, and I should have both my search and my login inside the same <form>??
    LVL 9

    Expert Comment

    Yes.  In ASP.NET applications all web controls must be contained within a single <form /> tag.  Be sure the tag contains the runat=server attribute.  It should look like this:

    <form id="Form1" method="post" runat="server"></form>

    If you're new to ASP.NET here's a couple resources you should check out:

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now