logo       

Re: how do i get the form name attribute value?: msg#00136

windows.devel.dotnet.web

Subject: Re: how do i get the form name attribute value?

The form name is one of those strange things that doesn't work in
asp.net like it does everywhere else. If you set a name on a form with
Runat="server", you can view the HTML source and see the asp.net has
changed your name and inserted the ID of the form. So even if you were
able to read the name, it wouldn't be what you were looking for. You
best bet is to use a new property of your choice to store this
information, and then read it in your class file. You could do that
like this:

.aspx file
<form id="Form1" runat="server" Name1="TEST">

.aspx.cs file
HtmlForm frm = (HtmlForm)this.FindControl("Form1");

//Note, you can use intellisense and see that frm.Name is a valid
property, //of the HtmlForm object, but if you look at the value of
frm.Name you will //see that it equals "Form1" regardless of what you
put in the field.
string name = frm.Attributes["Name1"];


Good Luck
MK


-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:DOTNET-WEB@xxxxxxxxxxxxxxxxxxx] On Behalf Of Alex Smotritsky
Sent: Monday, June 27, 2005 3:11 PM
To: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
Subject: Re: [DOTNET-WEB] how do i get the form name attribute value?

Unfortunately not.

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:DOTNET-WEB@xxxxxxxxxxxxxxxxxxx] On Behalf Of Christopher Reed
Sent: Monday, June 27, 2005 10:06 AM
To: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
Subject: Re: [DOTNET-WEB] how do i get the form name attribute value?

Name is a property of HtmlForm, so you should be able to use ctrl.Name.

Christopher Reed
Web Applications Supervisor
Information Technology
City of Lubbock
creed@xxxxxxxxxxxxxxxxxxxxx
"The oxen are slow, but the earth is patient."

>>> alex_smotritsky@xxxxxxxxx 6:41:24 AM 6/27/2005 >>>
I've added a name attribute to my webform and now would like to know how
to
read it. I think it should be easy since name is one of the standard
attributes of form.

I get the form id value like this:

string id = "";
foreach(Control ctrl in Page.Controls)
if (ctrl is System.Web.UI.HtmlControls.HtmlForm)
{
id = ctrl.ID;
break;
}

Don't see how to get name though, thanks for any help.

===================================
This list is hosted by DevelopMentor. http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r) http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise