Ver Mensaje Individual
  #4 (permalink)  
Antiguo 23/06/2004, 05:20
Avatar de GeRuNdIo
GeRuNdIo
 
Fecha de Ingreso: marzo-2004
Ubicación: Sanlúcar de Barrameda, Cádiz
Mensajes: 232
Antigüedad: 20 años, 1 mes
Puntos: 2
Hola de nuevo!!
Encontre algo de información para controlar el foco. (Cómo te dije.....JScript)

Te lo pasteo tal cual, se entiende bastante bien.(No hay ganas de traducir.....)

Changing Control Focus
The ASP.NET web controls provide a TabIndex property, but this property only applies to Internet Explorer and can't be used to programmatically set the focus to a control of your choice. To perform this task, you'll need the help of some JavaScript code. In this case, you need to find the JavaScript object that corresponds to the control, and call its focus() method.

The easiest way to handle this task is to create a function that accepts a control, extracts its client-side ID, and uses it to generate the JavaScript function required to set the focus to that control. You can then register this function so it will set the focus the next time the next time the page is sent to the user.

Here's the function you will need in C#:


private void SetFocus(Control ctrl)
{
// Define the JavaScript function for the specified control.
string focusScript = "<script language='javascript'>" +
"document.getElementById('" + ctrl.ClientID +
"').focus();</script>";

// Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript);
}

Here's the same function rewritten for VB .NET:


Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"

' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub

You can now call the custom SetFocus() function from any event handler to change the control focus as needed:


SetFocus(myTextBox);

Remember, the focus change won't take effect until the page is rendered and sent back to the browser.

Espero que te sirva de algo!!
__________________
Una buena forma de sacar las castañas del fuego sin quemarse: LEE FOROSDELWEB..... :si:
------
F.P.R. MCAD .NET