.NETGURU
Problem with Nested User Control in Form
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngreuse' list.


Thomas Stone
-- Moved from [aspngfreeforall] to [aspngreuse] by Marcie Jones <Click here to reveal e-mail address> --

Hi,

This seems like a really basic question to me...

I am trying to create a Web form -- a postback form. It has text fields and
such using HTML server controls. Some of them are standard across many
forms/uses, so I am placing them in a separate User Control (.ascx page) so
that I can reuse that chunk on multiple forms.

But when I register my user control on the Web form page, and use it on
that page, something odd is happening. The compiler is adding a prefix to
the ID of each HTML control in the user control's content. So if a text box
had an ID of Address, this is being turned into _ctrl2_Address or whatnot.
This then breaks any attempts to programmatically alter the properties of
such particular HTML controls (change their color, visibility, etc.),
during the Page_Load event of the page. I could of course change such
properties in the Page_Load *of the control*, but then I would be committed
to those values for all uses of the control. I want a plain user control
(set of HTML controls) that I can dress up with properties *on each of the
Web forms* that is registering and using it.

Isn't this possible? Can't this be done without creating and passing
properties into the user control? Can't be done on the Web form that uses
the user control? And why is the compiler altering the IDs of the HTML
controls in my user control (.ascx) page? How can I make it stop (since I
am assuming that would fix my problem here)? I am not using VS for these
pages, just Notepad for now (learning).

Thanks,

Tom S.

Reply to this message...
 
    
Alex Dresko
Well, I only partially know what's going on.. .NET is automatically
adding the prefix to your controls to prevent naming conflicts with
other controls. I think I read something about that in this same
newsgroup yesterday if you read back through the archives.

Alex Dresko
Three Point Oh!

-----Original Message-----
From: Thomas Stone [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 04, 2002 11:30 AM
To: aspngreuse
Subject: [aspngreuse] Problem with Nested User Control in Form

-- Moved from [aspngfreeforall] to [aspngreuse] by Marcie Jones
<Click here to reveal e-mail address> --

Hi,

This seems like a really basic question to me...

I am trying to create a Web form -- a postback form. It has text fields
and
such using HTML server controls. Some of them are standard across many
forms/uses, so I am placing them in a separate User Control (.ascx page)
so
that I can reuse that chunk on multiple forms.

But when I register my user control on the Web form page, and use it on
that page, something odd is happening. The compiler is adding a prefix
to
the ID of each HTML control in the user control's content. So if a text
box
had an ID of Address, this is being turned into _ctrl2_Address or
whatnot.
This then breaks any attempts to programmatically alter the properties
of
such particular HTML controls (change their color, visibility, etc.),
during the Page_Load event of the page. I could of course change such
properties in the Page_Load *of the control*, but then I would be
committed
to those values for all uses of the control. I want a plain user control

(set of HTML controls) that I can dress up with properties *on each of
the
Web forms* that is registering and using it.

Isn't this possible? Can't this be done without creating and passing
properties into the user control? Can't be done on the Web form that
uses
the user control? And why is the compiler altering the IDs of the HTML
controls in my user control (.ascx) page? How can I make it stop (since
I
am assuming that would fix my problem here)? I am not using VS for these

pages, just Notepad for now (learning).

Thanks,

Tom S.

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

Reply to this message...
 
    
Andy Smith
yes, the usercontrol id is being appended so there are no naming =
conflicts in the case of adding another instance of the same =
usercontrol.

in order to customize the internal controls of a usercontrol, I suggest =
you make public get-only properties that reference the controls you want =
to access.

so from your Page's Page_Load, you would do something like:
UserControl1.FirstTextBox.Visible =3D False

__
Andy Smith
Chief Code Monkey

[Original message clipped]

Reply to this message...
 
    
David Blankenbush
This behavior is by design and cannot be stopped. You should be using
properties for your control and using the page load in the control not the
form to alter color, visibility, etc. If you are trying to stay object
oriented then add the properties to the control. The form should not be
altering anything directly in your control.

The real issue comes into play when you write JavaScript to alter HTML on
the client. If you are writting the JavaScript on the fly then you have to
account for the prefixes that are added.

David

-----Original Message-----
From: Thomas Stone [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 04, 2002 11:30 AM
To: aspngreuse
Subject: [aspngreuse] Problem with Nested User Control in Form

-- Moved from [aspngfreeforall] to [aspngreuse] by Marcie Jones
<Click here to reveal e-mail address> --

Hi,

This seems like a really basic question to me...

I am trying to create a Web form -- a postback form. It has text fields and
such using HTML server controls. Some of them are standard across many
forms/uses, so I am placing them in a separate User Control (.ascx page) so
that I can reuse that chunk on multiple forms.

But when I register my user control on the Web form page, and use it on
that page, something odd is happening. The compiler is adding a prefix to
the ID of each HTML control in the user control's content. So if a text box
had an ID of Address, this is being turned into _ctrl2_Address or whatnot.
This then breaks any attempts to programmatically alter the properties of
such particular HTML controls (change their color, visibility, etc.),
during the Page_Load event of the page. I could of course change such
properties in the Page_Load *of the control*, but then I would be committed
to those values for all uses of the control. I want a plain user control
(set of HTML controls) that I can dress up with properties *on each of the
Web forms* that is registering and using it.

Isn't this possible? Can't this be done without creating and passing
properties into the user control? Can't be done on the Web form that uses
the user control? And why is the compiler altering the IDs of the HTML
controls in my user control (.ascx) page? How can I make it stop (since I
am assuming that would fix my problem here)? I am not using VS for these
pages, just Notepad for now (learning).

Thanks,

Tom S.

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

Reply to this message...
 
    
SHEATHER,Kristoffer (DITR)
ClientID is a property of Control (your control will inherit from this at s=
ome level) that contains the *FULL* ASP.NET generated id value. Use this w=
hen generating client-side JavaScript.

-----Original Message-----
From: David Blankenbush [mailto:Click here to reveal e-mail address]
Sent: Wednesday, 5 June 2002 2:07
To: aspngreuse
Subject: [aspngreuse] RE: Problem with Nested User Control in Form

This behavior is by design and cannot be stopped. You should be using
properties for your control and using the page load in the control not the
form to alter color, visibility, etc. If you are trying to stay object
oriented then add the properties to the control. The form should not be
altering anything directly in your control.

The real issue comes into play when you write JavaScript to alter HTML on
the client. If you are writting the JavaScript on the fly then you have to
account for the prefixes that are added.

David

-----Original Message-----
From: Thomas Stone [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 04, 2002 11:30 AM
To: aspngreuse
Subject: [aspngreuse] Problem with Nested User Control in Form

-- Moved from [aspngfreeforall] to [aspngreuse] by Marcie Jones
<Click here to reveal e-mail address> --

Hi,

This seems like a really basic question to me...

I am trying to create a Web form -- a postback form. It has text fields and
such using HTML server controls. Some of them are standard across many
forms/uses, so I am placing them in a separate User Control (.ascx page) so
that I can reuse that chunk on multiple forms.

But when I register my user control on the Web form page, and use it on
that page, something odd is happening. The compiler is adding a prefix to
the ID of each HTML control in the user control's content. So if a text box
had an ID of Address, this is being turned into _ctrl2_Address or whatnot.
This then breaks any attempts to programmatically alter the properties of
such particular HTML controls (change their color, visibility, etc.),
during the Page_Load event of the page. I could of course change such
properties in the Page_Load *of the control*, but then I would be committed
to those values for all uses of the control. I want a plain user control
(set of HTML controls) that I can dress up with properties *on each of the
Web forms* that is registering and using it.

Isn't this possible? Can't this be done without creating and passing
properties into the user control? Can't be done on the Web form that uses
the user control? And why is the compiler altering the IDs of the HTML
controls in my user control (.ascx) page? How can I make it stop (since I
am assuming that would fix my problem here)? I am not using VS for these
pages, just Notepad for now (learning).

Thanks,

Tom S.

| [aspngreuse] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp =3D JOIN/QUIT

| [aspngreuse] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp =3D JOIN/QUIT

Notice:
The information contained in this e-mail message and any attached files may
be confidential information, and may also be the subject of legal
professional privilege. If you are not the intended recipient any use,
disclosure or copying of this e-mail is unauthorised. If you have received
this e-mail in error, please notify the sender immediately by reply e-mail
and delete all copies of this transmission together with any attachments.

Reply to this message...
 
    
Trevor Pinkney
and... you call it by going

((Control)myDropDownList).ClientID

-Trev

At 03:17 PM 6/6/2002 +1000, you wrote:
[Original message clipped]

Reply to this message...
 
    
David Blankenbush
ASP.NET automatically generates a ClientID for a server control regardless
of whether you have specified an ID property for it or not. This property is
used to identify a control for client-side operations, such as ECMAScript
functions. Any name you assign to a server control using the ID property
overrides the value of this property.

-----Original Message-----
From: Trevor Pinkney [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 06, 2002 10:12 AM
To: aspngreuse
Subject: [aspngreuse] RE: Problem with Nested User Control in Form

and... you call it by going

((Control)myDropDownList).ClientID

-Trev

At 03:17 PM 6/6/2002 +1000, you wrote:
[Original message clipped]

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification