How to access the Form from the code behind? VB.NET

G

Guest

I have a form declared like this in the html

<form id="SearchResults" method="post" runat="server" name="frmMain"></form>

I don't see the form anywhere in the codebehind and I am not able to access
it like this
Me.frmMain or Me.SearchResults.
Is it not possible to access the form from the code behind or am I missing
something?

Thanks
 
K

Kevin Spencer

System.Web.UI.Page inherits System.Web.UI.Control, so you can identify any
Control in its immediate hierarchy via the Control.FindControl() method. To
access the Form, and it's child Controls, you would use
Page.FindControl("SearchResults") which returns the Form Control.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
G

Guest

Thanks

Is there any reason why it doesn't get declared in the codebehind when you
add the runat=server property value?

What I want to do is add an attribute the form.

Thank You for your help it is much appreciated.
 
K

Kevin Spencer

As the Form is a Control in the page, you can modify it the same way that
you would modify any other Control in the Page. Create a reference to it
using Page.FindControl as I mentioned, and then have your way with it! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top