473,405 Members | 2,279 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,405 software developers and data experts.

how to reset control ID numbering when databinding

Hi,

First some background: When you databind a repeater control, the controls
within the template are given an id like Repeater1:_ctl<n>:Button1 where <n>
increments for each repeater item. If you re-bind the control later on in
the page lifecycle, the contents are re-generated with the IDs starting from
0 again.

I have written my own templated control which mostly works except that if
you DataBind it more than once, the IDs don't start from 0 the second time.
So when a control inside the template causes a postback, the postback itself
happens but the control ID is not recognised and hence the OnBubbleEvent is
not called.

Can anyone explain where the control numbers are generated and how I get
them reset to 0 again?

TIA

Andy
Nov 19 '05 #1
2 2014
Hi Andy,

all I can say about it is: The index is calculated in the
"CreateControlHierarchy" method of the Repeater. It's protected and virtual
so you could override it (although i would not say you have to).

The Repeater saves the amount of bound items in the ViewState?!?! Maybe this
could cause your Repeater not behave correctly.

Why should you "re-bind" the repeater later on the same page again?

cu patrick

"Andy Fish" wrote:
Hi,

First some background: When you databind a repeater control, the controls
within the template are given an id like Repeater1:_ctl<n>:Button1 where <n>
increments for each repeater item. If you re-bind the control later on in
the page lifecycle, the contents are re-generated with the IDs starting from
0 again.

I have written my own templated control which mostly works except that if
you DataBind it more than once, the IDs don't start from 0 the second time.
So when a control inside the template causes a postback, the postback itself
happens but the control ID is not recognised and hence the OnBubbleEvent is
not called.

Can anyone explain where the control numbers are generated and how I get
them reset to 0 again?

TIA

Andy

Nov 19 '05 #2
"Patrick" <Pa*****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi Andy,

all I can say about it is: The index is calculated in the
"CreateControlHierarchy" method of the Repeater. It's protected and
virtual
so you could override it (although i would not say you have to).

I am actually using my own custom control, not a repeater. I think the index
created in the repeater code is not the one that's used to generate the
control IDs - it's so the caller can find out the index.
The Repeater saves the amount of bound items in the ViewState?!?! Maybe
this
could cause your Repeater not behave correctly.

Why should you "re-bind" the repeater later on the same page again?

The reason I have to re-bind it is that I'm not using viewstate. I need to
bind it in the load event so that events get through correctly. But if a
click event changes the data, I need to bind it again before rendering.

Anyway, I think I have solved the problem. In my implementation of
OnDataBinding() I was clearing most of the child controls out but leaving
one behind (one that was always required). That was what was causing the
numbering to go wrong. Now I have fixed it so that control is also deleted
and created on each databind and it all seems to work fine now.
cu patrick

"Andy Fish" wrote:
Hi,

First some background: When you databind a repeater control, the controls
within the template are given an id like Repeater1:_ctl<n>:Button1 where
<n>
increments for each repeater item. If you re-bind the control later on in
the page lifecycle, the contents are re-generated with the IDs starting
from
0 again.

I have written my own templated control which mostly works except that if
you DataBind it more than once, the IDs don't start from 0 the second
time.
So when a control inside the template causes a postback, the postback
itself
happens but the control ID is not recognised and hence the OnBubbleEvent
is
not called.

Can anyone explain where the control numbers are generated and how I get
them reset to 0 again?

TIA

Andy

Nov 19 '05 #3

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

Similar topics

3
by: trueblue7 | last post by:
I apologize if this question has been asked before... I'm trying to reset autonumber fields back to 1. The autonumber fields are part of the composite primary keys. I followed the MS help with...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
1
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and...
2
by: sck10 | last post by:
Hello, I have 3 repeater controls referencing the same function below. What it is doing is testing to see if the first column repeats itself and if so, add a line with the managers name. The...
6
by: AG | last post by:
I have a gridview with a template column containing an imagebutton to delete the row. Under some condition I don't want the row to be deleted, so would like to remove the button. In the...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
5
by: Mark Olbert | last post by:
It appears that FormView controls require the >>exact<< same layout of controls and control types in the various templates in order to function properly. Failure to do so results in a "failure to...
11
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.