Using two form runat-server in the same webform?

utilitaire

Regular
Joined
May 4, 2005
Messages
77
Using multiple forms in the same webform?

Is there ANY way to do this in classic asp.net ?

Here's my probleme:

All my webforms are enclosed with the "<form runat=sever" tag. In this form, I usualy validate the main topic of the page. However, I would like to be able to use other forms in the same page. The other forms dont have to be runat=server, be it'd be a very practical thing. Basically, here's an example of what I would like to do:


<form runat=server id="my main form">

//Here's my main form's input
<input type=text name=toto runat=server>
<input type=submit runat=server>

//Here's my second form
<form id="my second form">
<input type=text name=toto>
<input type=submit>
</form>
</form>

Is there any way to do that? I tried but it failed. It doesnt bug on the server-side, but in IE, the second form made the main form work wrong.
 
Last edited:
I can't think of any good reason to have two forms. Why do you need two forms? That may illicit more responses.
 
bri189a said:
I can't think of any good reason to have two forms. Why do you need two forms? That may illicit more responses.

Here's the page:

http://www.carrefourinternet.com/fr/admin/login.asp

Im programming the migration to ASP.NET. As you can see, there's two forms in the page. One in the center of the page, one at the top. They're both login forms. They both use «usager» and «password» input. I want these 2 forms to be independants. How would you do that? If I only make one form, 4 parameters will be pass in the form. Two «usager», and two «password». Isn't it bad? espacially when then input names are simillare. What solution do you propose? I would be sad to think of renaming the input names just because there's a conflict. These type of conflits has never been a problem in classic ASP, since we use to create two diffrent form. This brings another problem: if I want to put validators for the 4 inputs, these 4 validators will be validated EACH time IsPostBack = true. Witch is also wrong. I only want one of them to be validated.
 
Truthfully on the 'login' page itself I wouldn't have a duplicate place to log on...maybe in France that's typical, but in America it's not really seen...least by me and I'm on the internet a lot.

If you were to have it on both page I would use a user control that has the user name, password and submit button, it would then pass that to the security manager or whatever you use for validation.

As for validation, that would be rather complicated with the built in validators because you have the same control twice on a page, I'd have to do some thinking on that...but honestly why are there two logins on the same page? That's what's confusing me. Notice this page, Hotmail, Yahoo, etc... all only have one place to login.
 
Truthfully on the 'login' page itself I wouldn't have a duplicate place to log on...maybe in France that's typical, but in America it's not really seen...least by me and I'm on the internet a lot.

I agree. But this page was just an example. There's planty of pages that would need to use multiple form. I had to show you a page in witch you dont have to log-in. The login page itself was the first page I thought as an example. :)

If you were to have it on both page I would use a user control that has the user name, password and submit button, it would then pass that to the security manager or whatever you use for validation.

Right. But I cannot create another form in this control, right? So, if I want to send those inputs to the server, I'd have to do it in javascript? This kind of solution is good for a one time only, but not for a large web site. My web site has more than 400 asp pages. I dont want to deal with javascript each time I use another form.

but honestly why are there two logins on the same page? That's what's confusing me. Notice this page, Hotmail, Yahoo, etc... all only have one place to login.

As I said, the login page is just an example. Some of my pages have two, three, or illimited forms. Anyway, I always thought it was the best way to avoid unecessary bandwitch cost, since multiple form avoid all the inputs to be send each time I want only a few of them to be validated.

It think its weird that I cant find any tutorial on MSDN that explain how to do such basic thing. Visit http://www.msn.com and check the source. You will find At least 3 different forms in the same page. Even microsoft used to split their validation into multiple forms when necessary... :confused:
 
The thing is, like with any different technologies, that there is a diff. thinking behind it.

If you want to use ASP.NET you should start thinking in OOP.
For bigger websites you should first have a look at Masterpages.
Than, like in any good UI design, avoid anything that confuses the user.

And last, it really doesn't matter even on a 56k Modem to send 1K or 2K of userinput.
 
FZelle said:
The thing is, like with any different technologies, that there is a diff. thinking behind it.

If you want to use ASP.NET you should start thinking in OOP.
For bigger websites you should first have a look at Masterpages.
Than, like in any good UI design, avoid anything that confuses the user.

And last, it really doesn't matter even on a 56k Modem to send 1K or 2K of userinput.

First: Suppose you have a page with a list of textareas. Each textarea are editable. Your page has a capacity of 50 textareas. Each textarea contains a text that can be edited by the client. The good way to program this is to create 50 forms. One form for each textarea et one button submit per form. Therefor, the client dont send 50x15KO each time he wants to save one textarea. He only sends 1x15KO.

Second: this is not a professional way to do things. A professional application dont just send stuff to the server «just in case». A professional application has to be optimized. Even if in theory in doesn't consume a lot of bandwich, its still ugly to say, that in EVERY SINGLE PAGE, my web site will send too much data to the server, just because the programmers are too lazy to find a way to do things better.
 
If you want to use ASP.NET you should start thinking in OOP.

I'm very much into OOP.

For bigger websites you should first have a look at Masterpages.

I do.

Than, like in any good UI design, avoid anything that confuses the user.

I agree. But its not always easy to avoid multi-forms. MSDN explains that, in some case, its helpfull to have multi-forms. For instance, a page with a login form and, below, a register form(for non-members). How do you manage this? Of course you can use only one form with all inputs mixed-up. But its not a good way to program forms. If I write a login form, I dont wanna have to think about inputs names and inputs ID that I already used in the same page. I want to deal with theses inputs in a «local» context.
 
utilitaire said:
First: Suppose you have a page with a list of textareas. Each textarea are editable. Your page has a capacity of 50 textareas. Each textarea contains a text that can be edited by the client. The good way to program this is to create 50 forms. One form for each textarea et one button submit per form. Therefor, the client dont send 50x15KO each time he wants to save one textarea. He only sends 1x15KO.

ASP.NET doesn't work like that, if you had a page with 50 text areas and hit save, the ViewState, which is used to determine the differences between what a value was before posting the page and what the differance is when getting. yes, it's more data going back in the POST, and if you're that worried about a few K's of data, then use frames, as MSDN does in some places, but in all honestly, I think you're worrying about something that only someone on a 14.2 modem will notice. Most pages don't have 50 text boxes, at least if it's designed well, that would be a nightmare to use. Not to mention it would be nightmare to code, document, and support - in my opinion.
 
bri189a said:
ASP.NET doesn't work like that, if you had a page with 50 text areas and hit save, the ViewState, which is used to determine the differences between what a value was before posting the page and what the differance is when getting. yes, it's more data going back in the POST, and if you're that worried about a few K's of data, then use frames, as MSDN does in some places, but in all honestly, I think you're worrying about something that only someone on a 14.2 modem will notice. Most pages don't have 50 text boxes, at least if it's designed well, that would be a nightmare to use. Not to mention it would be nightmare to code, document, and support - in my opinion.

I agree: bandwich is not my principal concern here. I believe the worst part of having a single form is:


1) I cannot isolate inputs into a form. Therefor, many inputs can share the same ID/Name. It feels like you were coding a function in witch variables would be shared between all functions in the entire program. Isn't weird???

2) If I create a login form in a control, I cannot put a «form» tag into it, because it would enter in conflict with the main page form runat=server.

3) If I only want to validate certain inputs, It wont work: all validators in the whole page will be validated and error messages will appear everywhere, even if I didn't want them to in this particular action. It means that if I have 30 validators in the whole page, and the client hit a button somewhere, I cannot keep the page from validating ALL the validators even if those validators had nothing to do with the present hit. In other words, I cannot send a post request to validate only a section of my page. I have to validate all inputs EVERYTIME.
 
And by the way, for the bandwich thing: my web site has more than 4 millions hit per day. So I cannot really underestimate the benefit of the optimizating the data sent back and from the server. ;)
 
Back
Top