|
|
Subject:
Set Focus or Jump to a specific control web opening a web page -visual basic.net
Category: Computers > Programming Asked by: homebuilder-ga List Price: $5.00 |
Posted:
05 Mar 2003 10:05 PST
Expires: 04 Apr 2003 10:05 PST Question ID: 172178 |
|
Subject:
Re: Set Focus or Jump to a specific control web opening a web page -visual basic.net
Answered By: maxhodges-ga on 05 Mar 2003 18:56 PST Rated: |
homebuilder-ga, Interesting question! Here's your answer: onload="javascript:document.all.MyControl.focus()" where MyControl is the ID of the control to catch focus. [VISUAL BASIC] ' <summary> ' SetFocus ' Set Focus to a web control ' </summary> ' <param name="System.Web.UI.Control ctrl"></param> Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control) Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>" RegisterStartupScript("focus", s) End Sub Calling SetFocus( ) Me.SetFocus(Me.TextBox1) http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp Finally, one more approach. This C#, but I am sure you can understand the concept: this.Controls.Add(new LiteralControl("<Script Language=javascript>")); this.Controls.Add(new LiteralControl("document.forms[0].elements[MyControl].focus()")); this.Controls.Add(new LiteralControl("</Script>")); I hope this answer solves your problem. |
homebuilder-ga
rated this answer:
Fantastic, Thankyou very much! |
|
Subject:
Re: Set Focus or Jump to a specific control web opening a web page -visual basic.net
From: hatchetman-ga on 05 Mar 2003 12:31 PST |
body onload="document.MyForm.MyTextBox.focus();" |
Subject:
Re: Set Focus or Jump to a specific control web opening a web page -visual basic.net
From: mikviv-ga on 05 Mar 2003 14:34 PST |
<HTML> <HEAD> </HEAD> <BODY> <FORM onsubmit='return false' NAME=myForm> <INPUT NAME='myInput'> </FORM> <script> document.myForm.myInput.focus() </script> </BODY> </HTML> You need to wrap the input in a form element. The return false on the on submit is needed for not submitting the form, if you use it as a non-form control, otherwise if the text big is in a form that must be submitted, remove it. |
Subject:
Re: Set Focus or Jump to a specific control web opening a web page -visual basic.net
From: colinlarkin-ga on 30 Aug 2004 17:04 PDT |
onload="javascript:document.all.MyControl.focus()" I used this one, but IE in XP SP2 (not G-toolbar though) and NS block it as a Pop-up, is their another way? (apart from VB and C# as they are over my head) thanks ~cl |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |