Getting the name of the form in asp.net

G

Ghafran Abbas

Use this function to get the name of the form in asp.net.
This can be used if the name of the form on the client is needed, for
example, you might need the form name in javascript.
Modify the return to statement to return what is needed.
For the "ctrl" parameter, pass the page reference or any control
reference located inside the form.

==================Begin Code===============
Public Function GetFormName(ByVal ctrl As Control) As String

Dim p As Control = ctrl.Parent
While Not TypeOf p Is System.Web.UI.HtmlControls.HtmlForm
p = p.Parent
End While
Return p.ID 'Returns ID of Form
'Return p.ClientID 'Returns Generated ID of Form

End Function
==================End Code===============
 

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,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top