Hi,
How can i set focus on the first textbox control in a popup (modal)? It's a login window. I tried javascript, but that failed.
Hi,
How can i set focus on the first textbox control in a popup (modal)? It's a login window. I tried javascript, but that failed.
in the body onload
you can add some javascript
. and set focus to textbox you want
E.g:
<script type="text/javascript">
function setFocus() {
document.getElementById('TextBox2').focus();
}
</script>
<body onload="setFocus();">
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick='ani1();' />
</form>
</body>
The TextBox2
get focused once page is loaded
Just use focus()
in the onload
event in your ASP.NET page which declares your TextBox:
<body onload="document.getElementById('<%= yourTextBoxID.ClientID %>').focus();"></body>
You can use the <body>
tag with content placeholders or forms.
if you want to call the popup from js, use this:
function openPopup() {
$find('BehaviorID_of_your_popup').show();
document.getElementById('<%= theTextBox.ClientID %>').focus();
}
if you want to call it form server side, this should work:
protected void btnShow_Click(object sender, EventArgs e)
{
popup.Show();
theTextBox.Focus();
}