Setting focus to a control at server side.
-
Hi Guys, In my page I have two server side combo boxes (web controls), which are not visible when the page is loaded as they are positioned at the bottom side of the form (Means you have to scroll down). For example I have two combo boxes, one for country and other for states. As soon as the user selects any country respective states are added to the states combo box in the “SelectedIndexChanged” event of the country combo box and as the click event generates a post back the page is loaded again and the focus is again on the first control of the form. So the user has no idea where he was earlier and is very irritating too. How do I rectify this problem?? Your quick help in this regards will be appriciated. Thanks & Regards, Chintan :(( Chintan
-
Hi Guys, In my page I have two server side combo boxes (web controls), which are not visible when the page is loaded as they are positioned at the bottom side of the form (Means you have to scroll down). For example I have two combo boxes, one for country and other for states. As soon as the user selects any country respective states are added to the states combo box in the “SelectedIndexChanged” event of the country combo box and as the click event generates a post back the page is loaded again and the focus is again on the first control of the form. So the user has no idea where he was earlier and is very irritating too. How do I rectify this problem?? Your quick help in this regards will be appriciated. Thanks & Regards, Chintan :(( Chintan
Setting the SmartNavigation property of your <@page tag to True will solve your problem. <%@ Page SmartNavigation="True" Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication9.WebForm1"%>
-
Setting the SmartNavigation property of your <@page tag to True will solve your problem. <%@ Page SmartNavigation="True" Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication9.WebForm1"%>
Hi, Thanks a lot for your replay. Also I have got another solution for this problem. It may help you. I have written one common function in each code behind page. Private Sub FocusOnControl(ByVal name As String) Dim strBuilder As String = "" strBuilder += "" strBuilder += "document.getElementById('" + name + "').focus();" strBuilder += "" RegisterStartupScript("FocusOnControl", strBuilder) End Sub I am calling this function to set focus to any control from any procedure. For example on a click of a server side button if I want to set focus to a server side text box named 'txt1' then I just call the above function in the click event of the button as FocusOnControl("txt1"). This line does the needful to set focus to my text box. And this all is done in the code behind page. Once again thanks a lot for your reply. Regards, Chintan Chintan