Get Form ID at Runtime

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
 
O

Oliver

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?
 
J

Joe Gass

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top