A basic question

  • Thread starter Thread starter Rajesh C K R
  • Start date Start date
R

Rajesh C K R

Hi,

Why do some always needed to be placed inside a <form runat=server> where as
few other dont require that?

How do I know if a given control (derived from System.Web.UI.Control or
System.Web.UI.WebControls) will work outside <form runat=server>

For ex, I can place <asp:Table ...> outside a <form runat=server> but not
<asp:DropDownlist>

Is it based on the fact if the given control can do a post back or not??

Thanks in advance..


Rajesh
 
That is how html document object model is built.
Some html tags (text, textarea, select, checkbox, radio, button, submit),
must be placed inside a form tag.
Since web controls eventually are rendered to html elements,
they too have to follow these rules.
A table is not a form element, therefor it can be placed outside a form.
A DropDownlist is rendered to a select tag, which is a form element,
and must be placed inside a form.
 
Hi Sharon,

Thanks for your reply.

In that case- I created a user control (derived from
System.Web.UI.UserControl) without any html tags like textarea, select etc.
It just contains a table with few images.

Why this usercontrol is forced to be placed inside a form tag? I agree that
potentially I can place html text box in the user control. But currently i
have none.

Any better ideas for this scenario?

Rajesh
 
My guess is that UserControl must be placed inside a form,
to avoid potential form elements being placed out side a form.
 
Since the form tag can begin at the beginning of the body, and end at the
end of the body, I don't see why this should be an issue for you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Yes your right on the money Kevin. You can only have 1 <form
runat="server"> anyways. So, this should not be an issue
 
Only server side controls that you want/need to have their data posted back
to the server need to be put inside a <form runat=server>. I put server side
controls in the <head> tag all the time to specify <title> and <meta> directives,
but they don't accept user input and thus don't have anything to post back
to the server. Other controls such as Button, TextBox, DropDownList, etc
do need to go inside the <form runat=server>

-Brock
DevelopMentor
http://staff.develop.com/ballen
 

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

Back
Top