• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Setting focus on a textbox contained in a user control

I have a text box (txtSearch) that is part of a user control (Search.ascx), which in turn is part of a master page (Main.aspx). This form (user control) is used to search a database. There are radio buttons to select the type of search, the text box (txtSearch) and drop-downs that act as filters for the search. I need txtSearch to have focus when the page loads (Main.aspx). There are many articles on this subject and it seems like I've tried them all but nothing seems to work. Any ideas would be greatly appreciated!
0
jaysch
Asked:
jaysch
  • 2
1 Solution
 
b1xml2Commented:
<%@ Page Language="vb" %>
<script language="vb" runat="server">
Sub Page_Load(ByVal sender As Object,ByVal e As EventArgs)
Page.RegisterClientScriptBlock("startup","<script language='javascript'> window.onload = function () { document.getElementById('" & txtFocus.ClientID & "').focus()</script>")
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:TextBox Id="txtFocus" runat="Server" />
</form>
</body>
</html>
0
 
b1xml2Commented:
typo
===
Page.RegisterClientScriptBlock("startup","<script language='javascript'> window.onload = function () { document.getElementById('" & txtFocus.ClientID & "').focus() }</script>")
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now