1

I get inconsistent behavior when using repeater. I have a repeater with textboxes inside populated from a DataTable. Everything works perfectly for a while then the following error starts to popup.

Multiple controls with the same ID 'txt' were found. FindControl requires that controls have unique IDs.

The error seems to occur on the second session:

  1. Rebuild & Debug: Everything works perfectly.

  2. Stop debugging & Debug again: Error occurs indefinitely until rebuild.

Any ideas what can cause this ? Thanks in advance.

Ross
  • 63
  • 1
  • 1
  • 8

2 Answers2

0

Error shows that you are using same id for textboxes. You must have to use dynamic ids for textboxes like "txt_data_{uniqueId}" . Here uniqueId may be index or can use your primary key of data.

Here you can see answer for image tag : https://forums.asp.net/t/1655369.aspx?Multiple+controls+with+the+same+ID

This will help to you : Set ID of Items In a Repeater

Manjurhusen
  • 136
  • 2
  • 5
  • Thanks but I'm not sure that is the problem. The error only appears after the second debug. If the data repeater did not handle naming children correctly, shouldn't this error appear on the very first run? I will try manually naming my textboxes as suggested by the post, but I'm not sure I understand where exactly it goes wrong, it does seem like something is cached between runs. – Ross Oct 04 '18 at 09:14
0

The solution was pretty straight forward, but I was misled by the fact that this only started to occur on the second debug session.

I was using my own custom TextBox control with children, adding the following to my custom textbox solved the problem.

     public override string ID
    {

        get
        {
            return base.ID;

        }

        set
        {
            base.ID = value;

            if(mTextBox != null)
                mTextBox.ID = "txt" + base.ID;

        }
    }

However I would still like to understand why this problem would only start from the second debug session. I could reload the page 10+ times on the first session without any error and only when I restart debugging the error would appear.

The only cause I can think of is that aspx repeater caches data that conflicts ?

Ross
  • 63
  • 1
  • 1
  • 8