Get Form ID at Runtime

  • Thread starter Thread starter Earl Teigrob
  • Start date Start date
E

Earl Teigrob

I am inserting some Javacript into my page that requires the form name and
the tag name. I can get the tag name for the control by using
[tagname].ClientID but can not figure out a way to get the form ID. I notice
that .net usually names the from Form1 but I am not sure that I always count
on that???

So how can I get he client id of the form?

Earl
 
Hi Earl,

Most of the time, it will appear as

Page.Controls(1).ID

However, you don't really need it for JavaScript purposes. Since there's
only one form, you can reference it in JavaScript as

forms[0]

Does this help?
 
I use this

Private _formname As String = ""
Private Sub getFormClientId()

Dim p As Control = Me.Parent

While Not TypeOf p Is System.Web.UI.HtmlControls.HtmlForm

p = p.Parent

End While

_formname = p.ClientID

End Sub


Oliver said:
Hi Earl,

Most of the time, it will appear as

Page.Controls(1).ID

However, you don't really need it for JavaScript purposes. Since there's
only one form, you can reference it in JavaScript as

forms[0]

Does this help?


Earl Teigrob said:
I am inserting some Javacript into my page that requires the form name and
the tag name. I can get the tag name for the control by using
[tagname].ClientID but can not figure out a way to get the form ID. I notice
that .net usually names the from Form1 but I am not sure that I always count
on that???

So how can I get he client id of the form?

Earl
 
Back
Top