473,387 Members | 1,757 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,387 software developers and data experts.

Controls.Add() Problem in ASP.NET 2.0

Moving this code below from v1.1 to 2.0... am now getting this bug...

After I bind a repeater I move the repeater inside the placeholder
using controls.add(), but when I do this, all the children's clientids
change - I also ran a test and then moved the repeater again into a
third placeholder, and surely enough the clientid's change further.
The only work around I have found is to bind the repeater again after I
move the placeholder, but that just feels wrong.

// Bind Data
myRepeater.DataSource = new string[4];
myRepeater.DataBind();

// mClientIDBefore is now "myRepeater_ctl00"
string ClientIDBefore = myRepeater.Controls[0].ClientID;

// Move repeater inside a placeholder
myPlaceHolder.Controls.Add(myRepeater);

// ClientIDAfter is now "myRepeater_ctl04"
string ClientIDAfter = myRepeater.Controls[0].ClientID;

Sep 4 '06 #1
3 2230
Hi -

I have been able to replicate this exactly as you say - very weird!

I can see that this would be a problem with any View State reliant code
that you may use?!

James

Iain Buchanan wrote:
Moving this code below from v1.1 to 2.0... am now getting this bug...

After I bind a repeater I move the repeater inside the placeholder
using controls.add(), but when I do this, all the children's clientids
change - I also ran a test and then moved the repeater again into a
third placeholder, and surely enough the clientid's change further.
The only work around I have found is to bind the repeater again after I
move the placeholder, but that just feels wrong.

// Bind Data
myRepeater.DataSource = new string[4];
myRepeater.DataBind();

// mClientIDBefore is now "myRepeater_ctl00"
string ClientIDBefore = myRepeater.Controls[0].ClientID;

// Move repeater inside a placeholder
myPlaceHolder.Controls.Add(myRepeater);

// ClientIDAfter is now "myRepeater_ctl04"
string ClientIDAfter = myRepeater.Controls[0].ClientID;
Sep 4 '06 #2
Why don't you just put it to PlaceHolder first (the final place it's going
to be) and then dataBind once? ID changing makes sense. not just ClientID
but also UniqueID since that data is used when routing postback data. If
control is not where it's supposed to be per the ID path, how would
framework be able to locate control?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Iain Buchanan" <ja****@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Moving this code below from v1.1 to 2.0... am now getting this bug...

After I bind a repeater I move the repeater inside the placeholder
using controls.add(), but when I do this, all the children's clientids
change - I also ran a test and then moved the repeater again into a
third placeholder, and surely enough the clientid's change further.
The only work around I have found is to bind the repeater again after I
move the placeholder, but that just feels wrong.

// Bind Data
myRepeater.DataSource = new string[4];
myRepeater.DataBind();

// mClientIDBefore is now "myRepeater_ctl00"
string ClientIDBefore = myRepeater.Controls[0].ClientID;

// Move repeater inside a placeholder
myPlaceHolder.Controls.Add(myRepeater);

// ClientIDAfter is now "myRepeater_ctl04"
string ClientIDAfter = myRepeater.Controls[0].ClientID;

Sep 4 '06 #3
Because its being used in a dynamic site where the contents / position
is unknown at design time, The example code in the original post is
purely to prove that there is a potential issue with the repeater, the
original code is too large / complex to post. In the production app,
the control modifications are made during Init/Load/Render events in
order to rebuild the control heirarchy in the same format that it was
originally initialized. However viewstate is not the problem, the
problem is that when the child controls are initially added to the
repeater, the uniqueID/clientID properties are created (I need this
because I override the databind method of the repeater and inject the
clientid's elsewhere), however any re-assignedment of the repeater
forces the child controls to generate new uniqueID, when the only thing
that has changed is the parent property.

My first thought was that it was a heirarchy issue, but I've even tried
moving the repeater to one Placeholder and then back to its original
position (so the page's control heirarchy is exatly the same at time of
databind, however the clientid's are never the same.
Teemu Keiski wrote:
Why don't you just put it to PlaceHolder first (the final place it's going
to be) and then dataBind once? ID changing makes sense. not just ClientID
but also UniqueID since that data is used when routing postback data. If
control is not where it's supposed to be per the ID path, how would
framework be able to locate control?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Iain Buchanan" <ja****@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Moving this code below from v1.1 to 2.0... am now getting this bug...

After I bind a repeater I move the repeater inside the placeholder
using controls.add(), but when I do this, all the children's clientids
change - I also ran a test and then moved the repeater again into a
third placeholder, and surely enough the clientid's change further.
The only work around I have found is to bind the repeater again after I
move the placeholder, but that just feels wrong.

// Bind Data
myRepeater.DataSource = new string[4];
myRepeater.DataBind();

// mClientIDBefore is now "myRepeater_ctl00"
string ClientIDBefore = myRepeater.Controls[0].ClientID;

// Move repeater inside a placeholder
myPlaceHolder.Controls.Add(myRepeater);

// ClientIDAfter is now "myRepeater_ctl04"
string ClientIDAfter = myRepeater.Controls[0].ClientID;
Sep 4 '06 #4

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
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...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
5
by: Alex Nitulescu | last post by:
Hi. Because I'm a beginner in creating controls, I spent more than two *&^#$ hours to create this "login" as a custom control and to make it work properly: ...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
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...
0
JimWu
by: JimWu | last post by:
I have some problems in my code. The stutiation illustrate as the followsing statement. I use two pages, one, named "upload.aspx", is including several general html input tag, whose type are...
2
JimWu
by: JimWu | last post by:
Do anyone know how to layout in Panel control. The code as follows labels.Text = "Album Name :"; labels.Text = "Title :"; labels.Text = "Tag :"; labels.Text = "Description :";
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.