私は2つのビューを持っています。view1 の最後のコントロールは txtName で、view2 の最初のコントロールは txtAge です。TAB を押してフォーカスを txtName から txtAge に変更する必要がありますが、これを達成できません。
ASPX:
<asp:Multiview ID ="multiview1" runat="server" ActiveViewIndex="0">
<asp:view ID="view1" runat="server">
<asp:Textbox id="txtName" runat="server"
onfocusout="SetFocus('<%=txtAge.ClientId%>');"></asp:TextBox>
</asp:view>
<asp:view ID ="view2" runat="server">
<asp:Textbox id="txtAge" runat="server" ></asp:TextBox>
</asp:view>
</asp:Multiview>
JS:
function SetFocus(controlId){
/*alert(controlId);*/
document.getElementById(controlId).focus();
}
アラートを確認すると<%=txtAge.ClientId%>
、ポップアップに表示されます。これはどこが間違っているのでしょうか。
これが私の新しい発見です:
このコードは、ターゲット コントロールが同じビューにある場合はうまく機能しますが、別のビューにある場合は機能しません。したがって、最初にビューを変更してからフォーカスについて心配するために、何か他のことも行う必要があると思います。
<asp:Textbox id="txtName" runat="server"
onfocusout="SetFocus();"></asp:TextBox>
function SetFocus(){
document.getElementById('<%=txtEmail.ClientID%>').focus();
/* txtEmail is in the same view 'view1' as in txtName */
}