1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP.NET Multiple Forms

Discussion in 'C#' started by Aliniuz2, Feb 9, 2009.

  1. #1
    Hello.

    I am new to asp.net though i know php very well, and i watched and read several tutorials but i have a few doubts.
    I created a layout in XHTML/CSS first of all.

    Ok, I opened the Visual Studio 2008, created a new asp.net website, copy/pasted my XHTML code in the body tag and css file in the root folder of the website.

    My layout has in header a searchbox and a loginbox. That means two different forms. And if I put in each form the attribute runat="server" it dies an error.

    A page can have only one server-side Form tag.

    If I put runat="server" only at one of the two forms, the other form will not be functional?

    What should I do? I'm very confused. :(
     
    Aliniuz2, Feb 9, 2009 IP
  2. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #2
    Yes, you can not use more than one server side forms in the asp.net. Hence, only the server side form will be posted back to the server and you will not be able to read any values that are present in the other form that is not server side.

    It is to use only one server side form per asp.net
     
    MayurGondaliya, Feb 11, 2009 IP
  3. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #3
    You should not need 2 forms in asp.net. Just write your code in the click event handler of the buttons. You dont need the forms to post to a different page
     
    vihutuo, Feb 12, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    but if you have say two forms, lets say one login and one signup.. When the user presses enter (rather then click the button), it will not work properly. So you can use <asp:panel runat="server" DefaultButton="Button1"> , which will execute the Button1_Click event when the user presses enter after filling out that form.

    </asp:panel> must be added at the end of that particular form for it to work.
     
    camjohnson95, Feb 16, 2009 IP