Set focus on textbox

Discussion in 'ASP .Net' started by Saifee, Dec 8, 2003.

  1. Saifee

    Saifee Guest

    Hello,
    How do i set focus on text box or any web control in my
    aspx.vb page..pls help
     
    Saifee, Dec 8, 2003
    #1
    1. Advertisements

  2. Saifee

    lostinet Guest

    </form>
    <script>
    document.all.Button1.focus();
    </script>
    </body>
    </html>
     
    lostinet, Dec 8, 2003
    #2
    1. Advertisements

  3. Saifee

    Saifee Guest

    thanx for the script worked fine, but then how do i set
    the focus on a control in run time
    say if the user do not enter a value in a textbox,
    i dsiplay a message n then have to set the focus to the
    textbox
     
    Saifee, Dec 8, 2003
    #3
  4. Saifee

    vetri Guest

    Here is an example...

    <html>
    <body>
    <form runat="server">
    <asp:TextBox ID="TextBox1" RunAt="server" /><br>
    <asp:TextBox ID="TextBox2" RunAt="server" /><br>
    </form>
    </body>
    </html>

    <script language="javascript">
    document.forms[0].TextBox1.focus ();
    </script>
     
    vetri, Dec 8, 2003
    #4
  5. Saifee

    lostinet Guest

    <asp:placeholder id=script1 runat=server Visible=False
    EnableViewState=False>
    <script>
    alert('please input something');
    document.all.TextBox1.focus();
    </script>
    </asp:placeholder>
    </form>

    to enable the script once , using C#:

    placeholder.Visible=true;
     
    lostinet, Dec 8, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.