473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Controls ID are not being respected?

I have a Custom WebControl which adds several children at OnInit.
In OnInit I set the ChildControl to ParentID + "_" + Control's ID
so it would be something like MyContainer_VendorID
Now the control is moved to a TableCell in the Control's OnLoad event.
This control still has an ID of MyContainer_VendorID.
the Control is added to the Page. There the control has a value of
MyContainer_VendorID
In the Page's Render statement I overloaded it so i could put a breakpoint
and double check. so i checked myTable.Rows[AnIndex].Cells[5].Controls[0].ID
and sure enough the ID is MyContainer_VendorID.

When the page is rendered however it shows up as VendorID, and I do not see
why. the control always has a value of MyContainer_VendorID

WebControl_OnInit
Create Select
Give It ID OF VendorID
Give it new ID of ID + Vendor so it is now MyContainer_VendorID
AddControl to this.Controls
End Init

WebControl_OnLoad
Transfer all this.Controls to New TableRow as Cells
return this row as a property

Page_OnLoad
add the TableRow to our table
// here the Id is MyContainer_Vendor

Page_Render(
base.Render() //. here the Id is MyContainer_VendorID
now when the page is actually rendered the id is VendorID
I have NO idea how this is possible since before the control is added to the
WebControl's collection it is given the id of MyContainer_VendorID

Actual Debugger Excerpt
tblPOParts.Rows[1].Cells[4].Controls[0].ID "pork0_VendorID" string

protected override void Render(HtmlTextWriter writer)

{

base.Render (writer); // tblPOParts.Rows[1].Cells[4].Controls[0].ID
"pork0_VendorID" string
}
Nov 19 '05 #1
8 1551
You need to get the ClientID, not just the ID.
The reason they get named such ways is all about naming containers.
Here's more info:
http://msdn.microsoft.com/library/de...formspages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl...
I have a Custom WebControl which adds several children at OnInit.
In OnInit I set the ChildControl to ParentID + "_" + Control's ID
so it would be something like MyContainer_VendorID
Now the control is moved to a TableCell in the Control's OnLoad event.
This control still has an ID of MyContainer_VendorID.
the Control is added to the Page. There the control has a value of
MyContainer_VendorID
In the Page's Render statement I overloaded it so i could put a breakpoint
and double check. so i checked
myTable.Rows[AnIndex].Cells[5].Controls[0].ID and sure enough the ID is
MyContainer_VendorID.

When the page is rendered however it shows up as VendorID, and I do not
see why. the control always has a value of MyContainer_VendorID

WebControl_OnInit
Create Select
Give It ID OF VendorID
Give it new ID of ID + Vendor so it is now MyContainer_VendorID
AddControl to this.Controls
End Init

WebControl_OnLoad
Transfer all this.Controls to New TableRow as Cells
return this row as a property

Page_OnLoad
add the TableRow to our table
// here the Id is MyContainer_Vendor

Page_Render(
base.Render() //. here the Id is MyContainer_VendorID
now when the page is actually rendered the id is VendorID
I have NO idea how this is possible since before the control is added to
the WebControl's collection it is given the id of MyContainer_VendorID

Actual Debugger Excerpt
tblPOParts.Rows[1].Cells[4].Controls[0].ID "pork0_VendorID" string

protected override void Render(HtmlTextWriter writer)

{

base.Render (writer); // tblPOParts.Rows[1].Cells[4].Controls[0].ID
"pork0_VendorID" string
}

Nov 19 '05 #2
No that really does not help because my problem is that the ID is getting
set properly and it is retaining its value all the way up to and into
Page_Render but when the page renders the ID mysteriously is not what it was
at Page_Render
The problem is not setting them.
I am setting them

1) CreateControl
2) Give Name of VendorID
2) Give Name of ParentID + VendorID so name is now "MyContainer_VendorID" <<
Verified with the DEBUGGER
3) Add Control to WebControl.
4) Still has a ID of MyContainer_VendorID

5) in the Page_Render method
this.Controls[mytableindex].Rows[2].Cells[5].Controls[0].ID is
"MyContainer_VendorID";
Seen from the debugger again.

6) When it renders it spits out VendorID.
I am not sure why it is even remembering that VendorID
because nothing significant happens until it is given a new nickname

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
You need to get the ClientID, not just the ID.
The reason they get named such ways is all about naming containers.
Here's more info:
http://msdn.microsoft.com/library/de...formspages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl...
I have a Custom WebControl which adds several children at OnInit.
In OnInit I set the ChildControl to ParentID + "_" + Control's ID
so it would be something like MyContainer_VendorID
Now the control is moved to a TableCell in the Control's OnLoad event.
This control still has an ID of MyContainer_VendorID.
the Control is added to the Page. There the control has a value of
MyContainer_VendorID
In the Page's Render statement I overloaded it so i could put a
breakpoint and double check. so i checked
myTable.Rows[AnIndex].Cells[5].Controls[0].ID and sure enough the ID is
MyContainer_VendorID.

When the page is rendered however it shows up as VendorID, and I do not
see why. the control always has a value of MyContainer_VendorID

WebControl_OnInit
Create Select
Give It ID OF VendorID
Give it new ID of ID + Vendor so it is now MyContainer_VendorID
AddControl to this.Controls
End Init

WebControl_OnLoad
Transfer all this.Controls to New TableRow as Cells
return this row as a property

Page_OnLoad
add the TableRow to our table
// here the Id is MyContainer_Vendor

Page_Render(
base.Render() //. here the Id is MyContainer_VendorID
now when the page is actually rendered the id is VendorID
I have NO idea how this is possible since before the control is added to
the WebControl's collection it is given the id of MyContainer_VendorID

Actual Debugger Excerpt
tblPOParts.Rows[1].Cells[4].Controls[0].ID "pork0_VendorID" string

protected override void Render(HtmlTextWriter writer)

{

base.Render (writer); // tblPOParts.Rows[1].Cells[4].Controls[0].ID
"pork0_VendorID" string
}


Nov 19 '05 #3
As I said, do not look at the ID property to determine if it is what you
expected. This is not very reliable.
Instead, look at the ClientID property.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
No that really does not help because my problem is that the ID is getting
set properly and it is retaining its value all the way up to and into
Page_Render but when the page renders the ID mysteriously is not what it
was at Page_Render
The problem is not setting them.
I am setting them

1) CreateControl
2) Give Name of VendorID
2) Give Name of ParentID + VendorID so name is now "MyContainer_VendorID"
<< Verified with the DEBUGGER
3) Add Control to WebControl.
4) Still has a ID of MyContainer_VendorID

5) in the Page_Render method
this.Controls[mytableindex].Rows[2].Cells[5].Controls[0].ID is
"MyContainer_VendorID";
Seen from the debugger again.

6) When it renders it spits out VendorID.
I am not sure why it is even remembering that VendorID
because nothing significant happens until it is given a new nickname

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
You need to get the ClientID, not just the ID.
The reason they get named such ways is all about naming containers.
Here's more info:
http://msdn.microsoft.com/library/de...formspages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl...
I have a Custom WebControl which adds several children at OnInit.
In OnInit I set the ChildControl to ParentID + "_" + Control's ID
so it would be something like MyContainer_VendorID
Now the control is moved to a TableCell in the Control's OnLoad event.
This control still has an ID of MyContainer_VendorID.
the Control is added to the Page. There the control has a value of
MyContainer_VendorID
In the Page's Render statement I overloaded it so i could put a
breakpoint and double check. so i checked
myTable.Rows[AnIndex].Cells[5].Controls[0].ID and sure enough the ID is
MyContainer_VendorID.

When the page is rendered however it shows up as VendorID, and I do not
see why. the control always has a value of MyContainer_VendorID

WebControl_OnInit
Create Select
Give It ID OF VendorID
Give it new ID of ID + Vendor so it is now MyContainer_VendorID
AddControl to this.Controls
End Init

WebControl_OnLoad
Transfer all this.Controls to New TableRow as Cells
return this row as a property

Page_OnLoad
add the TableRow to our table
// here the Id is MyContainer_Vendor

Page_Render(
base.Render() //. here the Id is MyContainer_VendorID
now when the page is actually rendered the id is VendorID
I have NO idea how this is possible since before the control is added to
the WebControl's collection it is given the id of MyContainer_VendorID

Actual Debugger Excerpt
tblPOParts.Rows[1].Cells[4].Controls[0].ID "pork0_VendorID" string

protected override void Render(HtmlTextWriter writer)

{

base.Render (writer); // tblPOParts.Rows[1].Cells[4].Controls[0].ID
"pork0_VendorID" string
}



Nov 19 '05 #4
I guess I will restate my real question for the third time then.
WHY Is it behaving this way?

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
As I said, do not look at the ID property to determine if it is what you
expected. This is not very reliable.
Instead, look at the ClientID property.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
No that really does not help because my problem is that the ID is getting
set properly and it is retaining its value all the way up to and into
Page_Render but when the page renders the ID mysteriously is not what it
was at Page_Render
The problem is not setting them.
I am setting them

1) CreateControl
2) Give Name of VendorID
2) Give Name of ParentID + VendorID so name is now "MyContainer_VendorID"
<< Verified with the DEBUGGER
3) Add Control to WebControl.
4) Still has a ID of MyContainer_VendorID

5) in the Page_Render method
this.Controls[mytableindex].Rows[2].Cells[5].Controls[0].ID is
"MyContainer_VendorID";
Seen from the debugger again.

6) When it renders it spits out VendorID.
I am not sure why it is even remembering that VendorID
because nothing significant happens until it is given a new nickname

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
You need to get the ClientID, not just the ID.
The reason they get named such ways is all about naming containers.
Here's more info:
http://msdn.microsoft.com/library/de...formspages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<re****@community.nospam> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl...
I have a Custom WebControl which adds several children at OnInit.
In OnInit I set the ChildControl to ParentID + "_" + Control's ID
so it would be something like MyContainer_VendorID
Now the control is moved to a TableCell in the Control's OnLoad event.
This control still has an ID of MyContainer_VendorID.
the Control is added to the Page. There the control has a value of
MyContainer_VendorID
In the Page's Render statement I overloaded it so i could put a
breakpoint and double check. so i checked
myTable.Rows[AnIndex].Cells[5].Controls[0].ID and sure enough the ID is
MyContainer_VendorID.

When the page is rendered however it shows up as VendorID, and I do not
see why. the control always has a value of MyContainer_VendorID

WebControl_OnInit
Create Select
Give It ID OF VendorID
Give it new ID of ID + Vendor so it is now MyContainer_VendorID
AddControl to this.Controls
End Init

WebControl_OnLoad
Transfer all this.Controls to New TableRow as Cells
return this row as a property

Page_OnLoad
add the TableRow to our table
// here the Id is MyContainer_Vendor

Page_Render(
base.Render() //. here the Id is MyContainer_VendorID
now when the page is actually rendered the id is VendorID
I have NO idea how this is possible since before the control is added
to the WebControl's collection it is given the id of
MyContainer_VendorID

Actual Debugger Excerpt
tblPOParts.Rows[1].Cells[4].Controls[0].ID "pork0_VendorID" string

protected override void Render(HtmlTextWriter writer)

{

base.Render (writer); // tblPOParts.Rows[1].Cells[4].Controls[0].ID
"pork0_VendorID" string
}



Nov 19 '05 #5
Because an ID of a Control is not unique, which they should be on the
client (read: in the output html). For example, if you have a Repeater
with a Button with a certain ID, then the ID of each Button should be
unique.

ASP.NET solves this by not using the ID property as an ID on the
client, but by generating a ClientID in the PreRender phase of a
control's life cycle. The ClientID is based on a Control's ID and its
parent controls.

Whenever you need to refer to an ID of a control on the client, you
should use the ClientID, as Steve suggested, which is available to you
in the PreRender phase.

Nov 19 '05 #6
Right, I understand this and I was making the ID's Unique.
Hence why i was adding the ParentContainer.ID + "_" to the control's ID
However (for some reason asp.net is stripping it off) and when the form
posts back it says that the there are multiple controls with the same ID.
because there are.

Should I be "setting" the ClientID to whatever I want instead of
"getting" as Steve kept repeating? I had always assumed that the clientID
was something that one tried to avoid touching when creating web controls as
this could possibly break the control with the exact error I am getting in
certain scenarios.

"Wilco Bauwer" <wi****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Because an ID of a Control is not unique, which they should be on the
client (read: in the output html). For example, if you have a Repeater
with a Button with a certain ID, then the ID of each Button should be
unique.

ASP.NET solves this by not using the ID property as an ID on the
client, but by generating a ClientID in the PreRender phase of a
control's life cycle. The ClientID is based on a Control's ID and its
parent controls.

Whenever you need to refer to an ID of a control on the client, you
should use the ClientID, as Steve suggested, which is available to you
in the PreRender phase.

Nov 19 '05 #7
First of all, it seems weird if ASP.NET "strips" stuff from your ID.
How are you testing this?

Second of all, no, you should not (nor can you afaik) set the ClientID.
ClientID only exposes the ID which will be in the output (e.g. HTML).

Is there any reason you are trying to manually build a unique ID?
Contrary to your assumption, it _is_ wise to use ClientID, also in
webcontrols. Doing so shouldn't result in the error you get right now.
If you do, the source of the problem lies somewhere else (for example a
missing INamingContainer marker interface implemented by your composite
control).

Nov 19 '05 #8
I have a Web Control that creates about 20 Control's
the Control's are Created in OnInit
in Onit
Create NewControl
Set ID
call Base.Init (because the class is inhierted)
in Base.Init
Set ID of controls to ParentID + "_" + Existing ID
Add Control's to WebControl's Child Collection

Each control is wrapped inside a TableCell which is wrapped inside of a
TableRow which is exhibited as a property.
in the Page_Init
I create an array of these custom web controls
I give each WebControl an ID + its Index
I add the Custom WebControls to the Page's Control Collection
I then have a valid reference to the TableRow I need.
I add this TableRow to the Page's ServerSide Table.

Each row will have multiple DataControls with ID's that are givven the ID's
of
MyContainer1_VendorID
MyContainer2_VendorID
etc because there are multiple controls.

The reason I am building a Unique ID is because for some reason it is NOT
giving them a unique ID. And it seems to be thwarting my attempt to make
anyunique ID's by stripping the ID i give each control so that they all have
the same ID
MyControl1_VendorID becomes VendorID
MyControl2_VendorID becomes VendorID
MyControl33_VendorID becomes VendorID
MyControl35_VendorID becomes VendorID

This of course naturally creates a problem when posting back.
"Wilco Bauwer" <wi****@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
First of all, it seems weird if ASP.NET "strips" stuff from your ID.
How are you testing this?

Second of all, no, you should not (nor can you afaik) set the ClientID.
ClientID only exposes the ID which will be in the output (e.g. HTML).

Is there any reason you are trying to manually build a unique ID?
Contrary to your assumption, it _is_ wise to use ClientID, also in
webcontrols. Doing so shouldn't result in the error you get right now.
If you do, the source of the problem lies somewhere else (for example a
missing INamingContainer marker interface implemented by your composite
control).

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Andrew Chalk | last post by:
I have an ASP 3.0 page that contains an ActiveX control that I wrote in VC++ v6.0. Under Visual Interdev I can debug the ASP code just fine. However, when I get to an ASP line that references my...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
by: Mark Johnson | last post by:
Sometimes Controls that have been added to a GroupBox do not show up. What I am doing : 1) I am not using the designer, but create all the Controls per hand: groupBoxProdukt_01 = new...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
12
by: Dean Slindee | last post by:
In all instances where I show a form inside a control (tabpage, panel), the controls within the shown form are stretched vertically about 5% from the original. That is, if a textbox with an actual...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
3
by: =?iso-8859-1?Q?Daniel_Lidstr=F6m?= | last post by:
Hello! I have a strange problem with my pimpl implementation. What happens is that const correctness is not respected. Let me go straight to the code: #include <iostream> struct Geometry...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.