[thelist] no forms from with user controls?

Ken Schaefer ken.schaefer at gmail.com
Mon Oct 11 23:10:48 CDT 2004


Can I strongly suggest you go and buy the ASP.NET Unleashed book
mentioned earlier? Everything will be much, much clearer then.

With .NET v1/v1.1 you can, OOB, only have a single server-side form,
one that has:

<form runat="server"></form>

(ie a form that ASP.NET on the server-side is aware of). Since a user
control is designed to be re-used, you should not include a
server-side form tag inside the user control, since the user control
may, potentially, be placed on a page that already have a server-side
<form> tag in it.

To answer your question - you do not need a <form> tag to
implement/use a user-control per se. However, some things (such as
some server-side form web controls) need to be inside a <form> (just
like some HTML elements such as <input> need to be inside a <form>),
and if you use those inside your user control, then they need to be
inside a form at some point.

Note: you can have as many <form> tags as you like on a page - you can
only have a single server-side <form runat="server"> on a page.

OK, on the "Classic ASP" issue - who did this?

<% If foo then %>
<!-- #include -->
<% Else %>
<!-- #include -->
<%End if%>

ugh! That's yucky code :-)

To replicate this in ASP.NET, in the simplest form, you could have two
literal or panel controls, and you could do something like:

<script runat="server">
If foo then
   Panel1.Visible = True
Else
   Panel2.Visible = True
End If
</script>

Cheers
Ken


On Mon, 11 Oct 2004 22:19:29 -0500, Casey Crookston
<casey at thecrookstons.com> wrote:
> 
> 
> ----- Original Message -----
> From: "David Travis" <dwork at macam.ac.il>
> 
> > That's a very clear issue... think about it, ASCX is meant to be a control
> > within a ASPX file, which already contains a FORM tag
> 
> Okay, I seem to be missing a very basic aspect of an ASPX file.  Why, by
> default, does it have a FORM tag?  I am thinking of a FORM as in an HTML
> FORM with text boxes and drop down menues.  The ASPX file in which I am
> building dynamic content does not (unless I am missing something) have a
> form tag.  You don't need a form tag to implement user controls, do you?
> 
> Think, for a sedcond, like old server side include in classic asp.
> 
> I have a standard page... NOTHING dynamic, until we get to a certain point.
> At that point, we do a simple IF THEN.  IF A then INCLUDE FILE_A.  IF B then
> INCLUDE FILE_B.  Inside FILE_B is an html form.
> 
> Something like this would have been a snap in classic asp.  It's taking me 5
> hours to figure it out in ASP.NET.
> 
> Again, when responsing, please assume that I know NOTHING about ASP.NET (and
> you wil be right!!!)


More information about the thelist mailing list