Setting controls' name

G

Guest

I am dynamically creating TextArea and drop-down lists in ASP.NET using
something like HtmlTextArea eachTextArea = new HtmlTextArea();

I tried to set the "name" of these TextAreas, etc. (e.g. <textarea
name="NameOfTextArea" rows="5" cols="60">some text area</textarea>), as I
want to then dynamically read back the controls' values

Setting the ID attributes doesn't work, nor does the following:
eachTextArea.Attributes.Add("name","someName");

I am not allowed to set the UniqueID property, either!

How can I set the name property so I can read the values back on postback?
 
G

Guest

In addition, I have no idea why the controls were created as:
Form1:_ctl0, Form1:_ctl2, Form1:_ctl3
(i.e., there are no Form1:_ctl1)??
 
S

Steven Cheng[MSFT]

Hi Patrick,

Welcome to ASPNET newsgroup.
As for the setting ASP.NET server control's Name problem, here are some of
my understanding and suggestions:

The "name" attribute of ASP.NET server controls which is rendered to the
clientside browser is depend on the ID property of control. More exactly,
it's just the UniqueID of the control which represent the "name" attribute
rendering to clientside. However, the UniqueID can't be set directly and
is generated according to the "ID" property. And then we add top level(not
nested) controls onto asp.net page, the "UniqueID" will be identical to the
"ID". However, if the control is nested in other container controls(
NamingContainer), it's UniqueID(also clientID) will be generated derieved
from its parent contaner's UniqueID(clientID). So you'll see a hierarchical
named UniqueID when adding subcontrols into existing NamingContainer.

Also, as for your scenario, you're wanting to manually read the postback
value through the clientside "name" attribute, I 'd recommend that you use
the control.UniqueID to identify the control's postback value in the
Request.Form collection. Also, for dynamically added control, we can still
use it's Property to get the value , is there any particular problem you
met which prevent you from retrieving control's property value when posting
back?

Anyway, if there're any further questions, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| Thread-Topic: Setting controls' name
| thread-index: AcWTYY2DRpktsPrBTn+0CW17P5g+Ww==
| X-WBNR-Posting-Host: 198.240.128.75
| From: "=?Utf-8?B?UGF0cmljaw==?=" <[email protected]>
| References: <[email protected]>
| Subject: RE: Setting controls' name
| Date: Thu, 28 Jul 2005 03:46:04 -0700
| Lines: 12
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:114918
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| In addition, I have no idea why the controls were created as:
| Form1:_ctl0, Form1:_ctl2, Form1:_ctl3
| (i.e., there are no Form1:_ctl1)??
|
|
| "Patrick" wrote:
|
| > I am dynamically creating TextArea and drop-down lists in ASP.NET using
| > something like HtmlTextArea eachTextArea = new HtmlTextArea();
| >
| > I tried to set the "name" of these TextAreas, etc. (e.g. <textarea
| > name="NameOfTextArea" rows="5" cols="60">some text area
|
 
S

Steven Cheng[MSFT]

Hi Patrick,

Have you had a chance to see the suggestions in my last reply or have you
got any further progress on this issue? If there're anything else we can
help, please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 23156280
| References: <[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 29 Jul 2005 01:27:16 GMT
| Subject: RE: Setting controls' name
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 80
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:115072
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Hi Patrick,
|
| Welcome to ASPNET newsgroup.
| As for the setting ASP.NET server control's Name problem, here are some
of
| my understanding and suggestions:
|
| The "name" attribute of ASP.NET server controls which is rendered to the
| clientside browser is depend on the ID property of control. More exactly,
| it's just the UniqueID of the control which represent the "name"
attribute
| rendering to clientside. However, the UniqueID can't be set directly and
| is generated according to the "ID" property. And then we add top
level(not
| nested) controls onto asp.net page, the "UniqueID" will be identical to
the
| "ID". However, if the control is nested in other container controls(
| NamingContainer), it's UniqueID(also clientID) will be generated derieved
| from its parent contaner's UniqueID(clientID). So you'll see a
hierarchical
| named UniqueID when adding subcontrols into existing NamingContainer.
|
| Also, as for your scenario, you're wanting to manually read the postback
| value through the clientside "name" attribute, I 'd recommend that you
use
| the control.UniqueID to identify the control's postback value in the
| Request.Form collection. Also, for dynamically added control, we can
still
| use it's Property to get the value , is there any particular problem you
| met which prevent you from retrieving control's property value when
posting
| back?
|
| Anyway, if there're any further questions, please feel free to post here.
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
|
| --------------------
| | Thread-Topic: Setting controls' name
| | thread-index: AcWTYY2DRpktsPrBTn+0CW17P5g+Ww==
| | X-WBNR-Posting-Host: 198.240.128.75
| | From: "=?Utf-8?B?UGF0cmljaw==?=" <[email protected]>
| | References: <[email protected]>
| | Subject: RE: Setting controls' name
| | Date: Thu, 28 Jul 2005 03:46:04 -0700
| | Lines: 12
| | Message-ID: <[email protected]>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.aspnet:114918
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | In addition, I have no idea why the controls were created as:
| | Form1:_ctl0, Form1:_ctl2, Form1:_ctl3
| | (i.e., there are no Form1:_ctl1)??
| |
| |
| | "Patrick" wrote:
| |
| | > I am dynamically creating TextArea and drop-down lists in ASP.NET
using
| | > something like HtmlTextArea eachTextArea = new HtmlTextArea();
| | >
| | > I tried to set the "name" of these TextAreas, etc. (e.g. <textarea
| | > name="NameOfTextArea" rows="5" cols="60">some text area
| |
|
|
 

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

Top