get the form id programatically

F

francois

HI all,

How can i get hands on the Id of the form programmatically in the code
behind? In the debugger i see a Form property on the Page object but it
seems that i cannot access it, maybe it is a protected or private property?
Anyway how can I do to get (retrieve) the form Id programmatically in my
codebehind?

Many thanks,

Francois
 
B

bloomfield

I hope there is a better way than this until then here it is:

HtmlForm myFrom = (HtmlForm)Controls[1];
string myFromId = myFrom.ID;
(assuming the code is written in a page class)

ugly isn't it?
or a somehow a better way:

HtmlForm myFrom = null;
foreach(Control c in Controls)
{
if( c is HtmlForm )
{
myFrom = (HtmlForm)c;
break;
}
}
string myFromId = myFrom.ID;
(assuming the code is written in a page class)

It is always better to say what do you want to accomplish so that a
better/different/simpler approach can be suggested

Hope this helps
____________________
www.bloomfield.as.ro
 

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
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top