3

Overview: Clicking on text of first CheckBox in a repeater control clicks the last one. I know why this is happening; association of label tag with element id chkMarkedForDeletion and when that label is clicked it selects the last CheckBox, as all the CheckBoxes have same ID.. damn you repeater control!! I am wondering if there is any way to avoid this? Easy way would be to create individual labels and associate correctly to each CheckBox but that defeats the supposed default behaviour of a CheckBox.

Repeater code:

<asp:Repeater ID="childNodesDataRepeater" runat="server">
    <ItemTemplate>
        <table style="width: 100%;" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td style="width: 200px;">
                    <asp:CheckBox ID="chkMarkedForDeletion" runat="server" EnableViewState="true" Text="Remove"
                        Checked='<%# DataBinder.Eval(Container.DataItem, "IsMarkedForDeletion") %>' />
                </td>
                <td>
                    &nbsp;
                </td>
                <td style="width: 200px;">
                    <asp:CheckBox ID="chkHighImpactCause" runat="server" EnableViewState="true" Text="High Impact Cause"
                        Checked='<%# DataBinder.Eval(Container.DataItem, "IsHighPriority") %>' />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:Label ID="header002" runat="server" Text="What caused this problem?" />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:TextBox ID="txtProblemCausedBy" runat="server" EnableViewState="true" Width="100%"
                        Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' /><br />
                </td>
            </tr>
            <tr>
                <td colspan="3" style="height: 5px;">
                    <hr />
                    <asp:HiddenField ID="nodeIdentifier" runat="server" EnableViewState="true" Value='<%# DataBinder.Eval(Container.DataItem, "AnalysisID") %>' />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

Generated HTML Code for CheckBox:

<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl00$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>
...
...
<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl02$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>

Issue: Repeater Issue ScreenShot

Thanks, Abhi

7
  • What ASP.NET version are you running, and what is your Client ID generation policy? Commented Jan 23, 2013 at 18:32
  • Asp.NET 4.0; Client ID generation policy is default, I haven't marked it as Static. I tried changing the Client ID gen. policy but did not make much difference. :( Commented Jan 23, 2013 at 18:37
  • Well it should generate different IDs automatically, unless you set the ClientIDMode=Static. Does this happen on other repeaters? Commented Jan 23, 2013 at 18:54
  • Did you copy that generated HTML verbatim? Commented Jan 23, 2013 at 19:01
  • @RomanRoyter I haven't tried other repeaters yet. @ Mike No, I copied this from IE Developer tools, not from source code, I couldn't find anything generated for repeater there. Commented Jan 23, 2013 at 19:05

1 Answer 1

3

Make sure the ClientIDMode on the repeater is not set to "Static".

This setting is inheritable from the parent, which goes all the way up to web.config. So if you have to set the ClientIDMode explicitly on the repeater, it means that some parent overrides the default (Predictable) to "Static".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.