<form> element in pages running under a MasterPage

D

daveh551

I'm a little confused about something.

I have a "Contact Us" page that I'm developing that runs within a
content page under a master page.

I was plagiarizing fairly liberally from some other pages that I had
seen that worked, so I ended up with a <form> element containing a
number of text boxes, and a submit button.

In the codebehind for the button click event, where I went to
construct the mail message from the text in the textboxes, I found
that all of the text boxes were coming back as empty strings, even
though they were being displayed with text in them. I tried several
things to get it work right, and the thing that finally worked (or at
least the first thing that I tried that worked) was removing the
<form> element.

After doing some reading, I found that forms cannot be contained
within forms, and since the MasterPage places the ContentPlaceHolders
inside a <form> element, I needed to remove it. Is that a correct
understanding, and if so, how do you ever have a form on a content
page? Or do you even need it?
 
N

Nathan Sokalski

You simply do not need the <form> tag in the content page, because it is
already inside a <form> tag (the one in the Master Page). Because an ASP.NET
Page is only allowed to have one <form>, you do not need it. When creating a
Content Page, basically just pretend the <Content> tag is your <form> tag.
If you want to know more details (or for a better explanation, I'm not
always great at explaining things), just look up the details about Master
Pages, but it sounds to me like you've pretty much answered your own
question already. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top