Foros del Web » Programación para mayores de 30 ;) » .NET »

How can I set focus in a Textbox into a WebUserControl?

Estas en el tema de How can I set focus in a Textbox into a WebUserControl? en el foro de .NET en Foros del Web. Hello everybody: I have a WebUserControl embedded into a Web Form (I’m using C# .net). When I load Web Form I need to set the ...
  #1 (permalink)  
Antiguo 21/05/2004, 10:27
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
How can I set focus in a Textbox into a WebUserControl?

Hello everybody:
I have a WebUserControl embedded into a Web Form (I’m using C# .net).
When I load Web Form I need to set the cursor into a Textbox that is into WebUserControl.
In <body> of Web Form I have:
<body bgColor=”#ccfff MS_POSITIONING=”GridLayout” onload=”document.WUCDatos.TextBox2.focus(); “>
Where WUCDatos is form id of WebUserControl and TextBox2 is the Text Box into WebUserControl.
But this code doesn’t work.
I’ll appreciate your help.
A.L.
__________________
El hombre que tiene amigos ha de mostrarse amigo....
  #2 (permalink)  
Antiguo 21/05/2004, 11:37
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Hi see07, Don´t you speak spanish ? anyway... it doesn´t matter

Well..when you´re trying to set focus into a WC first of all y recommend you that check it source code (page processed) to see then name that recive the page (html) and then, copy and paste its "ID" and put it on you page.aspx

Sample..

wcSample .ascx
...
...
<asp:TextBox id="TextBox1 " runat="server"></asp:TextBox>

page .aspx

Cita:
..
...
<uc1:WebUserControl2 id="WebUserControl21 " runat="server"></uc1:WebUserControl2>
...
...
And when the page is sent to client (check source code) , and will be something like that..:

Cita:
...
...
<input name="WebUserControl21:TextBox1" type="text" id="WebUserControl21_TextBox1 " />
...
..
And then.. put it on you page the following:

Cita:
<body onload="document.getElementById('WebUserControl21_TextBox1' ).focus();">
I hope to be clear..

P.D.- Seguro que no hablas en español...?? (se me hace conocida tu bandera...)


See ya ...
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
  #3 (permalink)  
Antiguo 21/05/2004, 13:27
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
Hola Rootk:
Mejor te escribo en español (en el DF se habla español).
El códogo:
<input name="WebUserControl21:TextBox1" type="text" id="WebUserControl21_TextBox1 " />
no lo estoy poniendo ya que al cargar la web form automáticamente abre el WebUserControl.
El código:
<body onload="document.getElementById('WebUserControl21_ TextBox1' ).focus();">
si lo puse.
Sin embargo no posiciona el cursor en TextBox1.
Podrías ayudarme con esto?
Te lo agradeceré bastante....
__________________
El hombre que tiene amigos ha de mostrarse amigo....
  #4 (permalink)  
Antiguo 21/05/2004, 13:38
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Cita:
Mejor te escribo en español (en el DF se habla español).
De hecho yo tambien soy del d.f

En fin...

Cita:
El códogo:
<input name="WebUserControl21:TextBox1" type="text" id="WebUserControl21_TextBox1 " />
no lo estoy poniendo ya que al cargar la web form automáticamente abre el WebUserControl
Estoy de acuerdo.. lo que pasa esque te puse ese ejemplo porque así es como se ve cuando tu aplicacion corre en el cliente...(ya está procesado)

Es decir.. ejecuta tu aplicacion y ve el codigo fuente y busca tu web control y el nombre del ID es el que vas a poner en tu getElementById...,

Si me explico ??

Saludos
  #5 (permalink)  
Antiguo 24/05/2004, 09:30
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
Gracias amigo Rootk por tus sugerencias, finalmente lka manera en que logré hacerlo fue:
<body bgColor=”#ccfff MS_POSITIONING=”GridLayout” onload=”document.forms[0].WUCDatos1_TextBox2.focus();“>
Si tienes más de 1 WebUserControl cambia [0] por [1] y así y así…
__________________
El hombre que tiene amigos ha de mostrarse amigo....
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:45.