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
 
Ad

Advertisements

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.
 
Ad

Advertisements

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.
 

Top