Setting a WebControls TabIndex based on the ControlId of another control

Posted by Daniel Ballinger on Stack Overflow See other posts from Stack Overflow or by Daniel Ballinger
Published on 2010-04-01T00:21:12Z Indexed on 2010/04/01 0:23 UTC
Read the original article Hit count: 731

I have an ASP.NET Webforms site that is regularly having features added. The majority of time a new WebControl is added to the page and I need to increment the TabIndex to all subsequent controls on the page.

I'd prefer a more robust solution than choosing an arbitrary gap between the initial assigned tab indexes. Setting the tab indexes using the designer tab order functionality is one option but I'd prefer to stay in the source view.

Ideally, if I had three check boxes I'd like to be able to define the tabindex based off the previous controls tabindex. Then I'd only need to insert the new control and change one existing control.

<asp:CheckBox ID="checkBoxA" runat="server" TabIndex="0"/>
<asp:CheckBox ID="checkBoxB" runat="server" TabIndexAfterControlId="checkBoxA"/>
<asp:CheckBox ID="checkBoxC" runat="server" TabIndexAfterControlId="checkBoxB"/>

My first thought was to extend System.Web.UI.WebControls.WebControl with a new property, but extension properties aren't supported.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about tabindex