Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Setting focus to a control at server side.

Setting focus to a control at server side.

Scheduled Pinned Locked Moved ASP.NET
helpquestionsysadmintutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chintan1979
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • C chintan1979

      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

      S Offline
      S Offline
      Syed Abdul Khader
      wrote on last edited by
      #2

      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"%>

      C 1 Reply Last reply
      0
      • S Syed Abdul Khader

        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"%>

        C Offline
        C Offline
        chintan1979
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups