Welcome Guest Search | Active Topics | Sign In | Register

Set Focus on Textbox into Dialog Options
OBSS
Posted: Friday, May 1, 2009 8:19:54 AM
Rank: Newbie
Groups: Member

Joined: 5/1/2009
Posts: 4
I have a Dialog Modal, inside a textbox. How Set focs on the textbox at open the Dialog?
eo_support
Posted: Friday, May 1, 2009 9:12:28 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Please try the following code:

Code: JavaScript
//Call this function to display the dialog
function showDialog()
{
    eo_GetObject("Dialog1").show();
}

//This function is called by the dialog when
//it is shown. 
function init_dialog(dialog, arg)
{
    //Get the textbox you wish to focus. Note
    //the server code syntax here
    var textBox = document.getElementById('<%=Dialog1.ContentContainer.FindControl("TextBox2").ClientID%>');
	
    //Set the focus to the textbox. A slight
    //delay is needed because the dialog always
    //try to set the focus to the first input
    //element. So our focus code must be run
    //after that
    setTimeout(
        function()
        {
            textBox.focus();
        }, 200);
}


Code: HTML/ASPX
<a href="javascript:showDialog();">Show Dialog</a>
<eo:Dialog id="Dialog1" ClientSideOnInitDialog="init_dialog" ....>
....
</eo:Dialog>


Note the dialog's ClientSideOnInitDialog is set to "init_dialog", which is the name of the JavaScript function that focus the textbox.

Thanks!
OBSS
Posted: Friday, May 1, 2009 11:32:33 AM
Rank: Newbie
Groups: Member

Joined: 5/1/2009
Posts: 4
Thank you, for the response.
I have the following mistake:
Error de servidor en la aplicación '/GesSat'.


Error del analizador
Descripción: Error al analizar el recurso requerido para dar servicio a esta solicitud. Revise los detalles de error de análisis específicos y modifique el archivo de código fuente en consecuencia.

Mensaje de error del analizador: La expresión de un bloque <%= %> o <%# %> no puede ser una cadena vacía.

Error de código fuente:


Línea 25: function init_dialog(dialog, arg) {
Línea 26: //Get the textbox you wish to focus. Note
Línea 27: //the server code syntax <%= %> here
Línea 28: var textBox = document.getElementById('<%=Dialog1.ContentContainer.FindControl("TxtIncidencia").ClientID%>');
Línea 29:


Archivo de origen: /GesSat/Ordenes.aspx Línea: 27



Información de versión: Versión de Microsoft .NET Framework:2.0.50727.3053; Versión ASP.NET:2.0.50727.3053
eo_support
Posted: Friday, May 1, 2009 11:36:10 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Please remove the following comment line:

Línea 27: //the server code syntax <%= %> here

That is meant to be a comment line but ASP.NET picked up "<%= %>" in the comment and does not like it.

Thanks
OBSS
Posted: Friday, May 1, 2009 11:50:23 AM
Rank: Newbie
Groups: Member

Joined: 5/1/2009
Posts: 4
Thank you, for the response.
I have the following mistake:
Error de servidor en la aplicación '/GesSat'.

function init_dialog(dialog, arg) {
var textBox = document.getElementById('<%=DialogIncidencia.ContentContainer.FindControl("TxtIncidencia").ClientID%>');
setTimeout(
function() {
textBox.focus();
}, 200);
}

La colección de controles no puede modificarse porque el control contiene bloques de código (por ej. <% ... %>).
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.

Detalles de la excepción: System.Web.HttpException: La colección de controles no puede modificarse porque el control contiene bloques de código (por ej. <% ... %>).

Error de código fuente:

Se ha generado una excepción no controlada durante la ejecución de la solicitud Web actual. La información sobre el origen y la ubicación de la excepción pueden identificarse utilizando la excepción del seguimiento de la pila siguiente.

Seguimiento de la pila:


[HttpException (0x80004005): La colección de controles no puede modificarse porque el control contiene bloques de código (por ej. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +8674071
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:303
AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:307
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627





Información de versión: Versión de Microsoft .NET Framework:2.0.50727.3053; Versión ASP.NET:2.0.50727.3053
eo_support
Posted: Friday, May 1, 2009 12:09:13 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

That is something else. It basically complains that you can not use server code block (<%= %>) and trying to modify the parent control's control collection (usually because you want to dynamically create controls) at the same. This is a generic ASP.NET restriction and it has nothing to do with us. The issue is triggered because you are modifying the control collection, and our sample code uses server code block. In order to resolve the issue, you need to remove at least one.

There are many ways to remove server code block from our code, all of which is related to general ASP.NET/JavaScript programming and none is particular related to us. One way you can try is:

1. Add the following code in your server side code:

Page.RegisterClientScriptBlock("control_to_focus",
string.Format("<script type='text/javascript'>var control_to_focus='{0}';</script>",
Dialog1.ContentContainer.FindControl("TextBox1").ClientID));

This stores the ID of the TextBox control you want to focus inside a JavaScript variable "control_to_focus";

2. Change the client side JavaScript code to:

Code: JavaScript
var textBox = document.getElementById(control_to_focus);


This way it removes the server code block that was used by getElementById. And your original problem should go away.

Thanks!

OBSS
Posted: Friday, May 1, 2009 1:04:07 PM
Rank: Newbie
Groups: Member

Joined: 5/1/2009
Posts: 4
Thank you very much, with this it is solved.
Thiago Diniz
Posted: Monday, May 4, 2009 8:44:29 AM
Rank: Newbie
Groups: Member

Joined: 2/5/2009
Posts: 5
Hi,

I solve this problem placing the text box as the first control of the dialog on the *.aspx page code. It works fine for me, and is a lot easier to do.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.