Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Note: This approach worked for some webcontrols (DropDownLists) but not all of them (CheckBoxes). I've left it here for reference.</strong></p> <p>I've ended up with a solution that uses a code behind method to capture the relationship between controls.</p> <pre><code>&lt;asp:CheckBox ID="checkBoxA" runat="server" TabIndex="1"/&gt; &lt;asp:CheckBox ID="checkBoxB" runat="server" TabIndex='&lt;%# TabIndexAfter(checkBoxB, checkBoxA) %&gt;'/&gt; &lt;asp:CheckBox ID="checkBoxC" runat="server" TabIndex='&lt;%# TabIndexAfter(checkBoxC, checkBoxB) %&gt;'/&gt; </code></pre> <p>The code behind method will initially do a basic TabIndex assignment, which works well when the tab order follows the order of the controls on a page. Then during the PreRender event the tab index order will be checked again. This is important if the tab order doesn't not follow the natural flow of the page.</p> <pre><code> private LinkedList&lt;WebControl&gt; _webControlTabOrder; /// &lt;summary&gt; /// Assign the current WebControl TabIndex a value greater than the prior WebControl. /// &lt;/summary&gt; /// &lt;param name="currentWebControl"&gt;The current WebControl to set the TabIndex for&lt;/param&gt; /// &lt;param name="priorWebControl"&gt;The prior WebControl to get the previous TabIndex from.&lt;/param&gt; /// &lt;returns&gt;The new TabIndex for the control&lt;/returns&gt; public int TabIndexAfter(WebControl currentWebControl, WebControl priorWebControl) { if (_webControlTabOrder == null) { _webControlTabOrder = new LinkedList&lt;WebControl&gt;(); this.PreRender += new EventHandler(UserControlBase_PreRender); } LinkedListNode&lt;WebControl&gt; priorNode = _webControlTabOrder.Find(currentWebControl); if (priorNode == null) { priorNode = _webControlTabOrder.AddLast(priorWebControl); } _webControlTabOrder.AddAfter(priorNode, currentWebControl); return priorWebControl.TabIndex + 1; } void UserControlBase_PreRender(object sender, EventArgs e) { LinkedListNode&lt;WebControl&gt; currentNode = _webControlTabOrder.First; while(currentNode.Next != null) { LinkedListNode&lt;WebControl&gt; nextNode = currentNode.Next; if (nextNode.Value.TabIndex &lt;= currentNode.Value.TabIndex) { nextNode.Value.TabIndex = (short)(currentNode.Value.TabIndex + 1); } currentNode = nextNode; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload