开发者

setting input field focus using jQuery on ASP.NET page user control

开发者 https://www.devze.com 2023-03-30 23:30 出处:网络
How would I set focus on the TxtPassword input field from this page using jQuery?The TxtPassword input field lives in the SaveCancelDelete user control.

How would I set focus on the TxtPassword input field from this page using jQuery? The TxtPassword input field lives in the SaveCancelDelete user control.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="BatchDetails.aspx.vb"
    Inherits="Acu.UI.Web.AccessioningBatchDetails" MasterPageFile="~/Master" %>

<%@ Register TagPrefix="uc1" TagName="SaveCancelDelete" Src="/SecurityDisplay/SaveCancelDelete.ascx" %>
<%@ Register TagPrefix="uc1" TagName="BatchEditor" Src="BatchEditor.ascx" %>
<%@ Register TagPrefix="uc1" TagName="PageHTMLTop" Src="/PageHTMLTop.ascx" %>
<%@ Register TagPrefix="uc1" TagName="PageHTMLRight" Src="/PageHTMLRight.ascx" %>
<%@ Register TagPrefix="uc1" TagName="AccessioningHTMLLeft" Src="/Accessioning/Accessi开发者_开发问答oningHTMLLeft.ascx" %>
<%@ Register TagPrefix="uibox1" Namespace="Acu.UI.Web" Assembly="Acu.UI.Web" %>

<asp:Content runat="server" ID="headcontent" ContentPlaceHolderID="head">
</asp:Content>
<asp:Content runat="server" ID="bodycontent" ContentPlaceHolderID="body">
    <uc1:PageHTMLTop id="PageHTMLTop" runat="server" />
    <uibox1:UIBox ID="BxWizardTitle" runat="server" Width="100%">
        <uc1:AccessioningHTMLLeft id="AccessioningHTMLLeft" title="Accessioning Dashboard"
            runat="server" />
        <uc1:BatchEditor ID="BatchEditor" runat="server" />
        <uc1:PageHTMLRight id="PageHTMLRight" runat="server" />
    </uibox1:UIBox>
    <uc1:SaveCancelDelete id="SaveCancelDelete" runat="server" />

    <script type="text/javascript">

    jQuery(document).ready(function() {
        //jQuery('#<%=TxtPassword.ClientID %>').focus();  
        //jQuery("#ctl00_body_SaveCancelDelete_TxtPassword").focus();
    });

    </script>

</asp:Content>


The [name$=""] selector searches for a control with a name that ends with whatever is specified in the quotes.

$('input[name$="TxtPassword"]').focus(); 


Use attribute contains(*=) selector.

jQuery(document).ready(function() {
    jQuery("input[id*='TxtPassword']", $("[id*='SaveCancelDelete'")).focus();  
});


You need a property on the uc1:SaveCancelDelete that gives you the client id of the passwort control, because you need this. On the other hand, if the password field is a visible property of the usercontrol, you could use server-side code to call SaveCancelDelete.PasswordInputControl.Focus(); from your codebehind.

0

精彩评论

暂无评论...
验证码 换一张
取 消