Form Tag of Current Page?

  • Thread starter Thread starter sc
  • Start date Start date
S

sc

From my codebehind, I am trying to get an object reference to the
current form, so I can perform a FindControl and work with one of the
child controls.

My problem is that I never know the name of the control. How to find
that (using Reflection?)?

Thanks.
 
Hi, sc:

Well, one not-so-robust way of finding the form control for a page is to
iterate through the page's controls until you find one that is of type
HtmlForm. Some sample VB code follows.

-------------
' Iterate the Page's controls for the HtmlForm
dim MyForm as HtmlForm
for each control as Control in Page.Controls
if TypeOf control is HtmlForm then
MyForm = CType(control, HtmlForm)
exit for
end if
next

' Test for a match
' *** This really isn't necessary since there has to be a match for server
other controls to even work
if not MyForm is Nothing then
' Do something with the form control
end if
-------------

This isn't ideal, I know. However, considering the page control tree, it
hasn't taken very long at all to find the form control in my tests.

Hope this helps,
Matt
 
Back
Top