Two methods
1. Setup the Tab index's for your controls so that the one that needs focus is 0 next is 1 next is 2... and so on
2. Use some client side javascript to do the job. Link 9 wrote some nice functions that you should be able to use. You can find them here. thread855-292711
HTH That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
Yo Jack what namespace did you import to use RegisterStartupScript?
Or have I finally reached that land of pink and purple poka dots? That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
uh...you've reached the land of pink and purple poka dots...or more accurately, the land of the black and blue western conference wannabe's, cause HER COME THE BOMBERS! OH YEAH!
ok, now that thats been said...
I didn't have to import anything to my knowledge, Mark. I found that code over a year ago online, and just used it directly in our project.
I'll check work on Tuesday and give you a difinitive answer, but right now, I don't think there's anything that needs to be imported
Funny cause VS gets mad at me when I try to type RegisterStartupScript That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
The intellisense won't bring it up but I get no error and it works. Now to see if I can't get it working in my user controls, because there it is giving me an blue squiggly.
aha.. You must add Page.registerStartupScript.
For anyone who is interested you need to make a small tweak to get the function to work from within a user control.
Public Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim sb As New StringBuilder()
sb.Append("<SCRIPT language='javascript'>document.getElementById('" sb.Append(Me.UniqueID)
sb.Append(":"
sb.Append(ctrl.ID)
sb.Append("').focus() </SCRIPT>"
The bolded lines must be added as "ControlID:" is added before the control when it gets to the browser. If you didn't understand what I said then just copy and trust.
Over and out! That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
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
uh how is that different than Jacks solution?
As I said above I did get this working anyway twas just a silly mistake. That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
I have a question about passing the control to this sub. Do you do it on the page or in another sub. Right now when I send it from another sub nothing happens?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.