473,472 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Focus on a text box / AJAX and MasterPage

3 New Member
Hello,

Here is what I need:
I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback.
Here is the problem:
I am using AJAX and MasterPages as well as an update panel, the textbox is in a panel. I have tried to do it using different java scripts but I can't get it to work because I am not using asp forms, instead I am using Containers.

Here is my code:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="infcontrol.aspx.vb" Inherits="orders_CutGroupAssign" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language=javascript>
function setFocus(ctl) {
if (document.forms[0][ctl] != null)
document.forms[0][ctl].focus();
}
setFocus("txtGT")
</script>
<asp:UpdateProgress ID="UpdPrgInf" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
DisplayAfter="1">
<ProgressTemplate>
<img src="../images/wait.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Label ID="lblTitleApp" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#FF8000"
Text="Control de Infladores"></asp:Label><br />
<asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ReceivingDBConnectionString %>" SelectCommand="eK_IW_GetOpenOrders" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter DefaultValue="IRS" Name="PlantID" SessionField="Planta" Type="String" />
</SelectParameters>
</asp:SqlDataSource> <asp:Panel id="pnlStatus" runat="server" Height="30px" Width="645px" BackColor="#E0E0E0"><TABLE style="WIDTH: 640px"><TBODY><TR><TD style="HEIGHT: 18px; width: 178px; text-align: right;">
<asp:Label id="Label1" runat="server" Font-Size="10pt" Text="Ordenes Pendientes de Surtir: " Width="175px"></asp:Label></TD><TD style="HEIGHT: 18px; width: 225px; text-align: left;"> <asp:DropDownList id="cboOrders" runat="server" DataSourceID="SqlDataSource2" OnSelectedIndexChanged="cboOrders_SelectedIndexCha nged" AutoPostBack="True" DataTextField="Ordernumber" DataValueField="Ordernumber"></asp:DropDownList>
<asp:TextBox id="txtOrderScan" runat="server" AutoPostBack="True" OnTextChanged="txtOrderScan_TextChanged" Width="125px"></asp:TextBox></TD><TD style="HEIGHT: 18px; width: 78px; text-align: left;"> <asp:Label id="lblInvalidOrder" runat="server" Font-Bold="True" ForeColor="Red" Text="Orden Inválida" Visible="False"></asp:Label></TD><TD style="WIDTH: 29px; HEIGHT: 18px; text-align: right;"> <asp:Button id="btnCancelOrder" runat="server" Text="Cancelar Orden" Visible="False" OnClick="btnCancelOrder_Click"></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <BR /><asp:Label id="lblStatus" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="RoyalBlue" Width="568px" Text="Status Orden" Visible="False"></asp:Label><BR />
<asp:Panel id="pnlSupply" runat="server" Width="650px"><SPAN style="FONT-SIZE: 10pt">Especifique el numero de parte del material que va a surtir y la cantidad para&nbsp;esta orden:<BR />&nbsp;</SPAN><TABLE style="WIDTH: 648px; HEIGHT: 1px"><TBODY><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 70px; HEIGHT: 41px; TEXT-ALIGN: right">Número de parte</TD><TD style="VERTICAL-ALIGN: top; WIDTH: 159px; HEIGHT: 41px"><asp:TextBox id="txtPartNumber" runat="server" MaxLength="25"></asp:TextBox><BR /><asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" Width="120px" ControlToValidate="txtPartNumber" ErrorMessage="Máximo 25 caracteres." ValidationExpression=".{0,25}" Display="Dynamic" Font-Bold="False"></asp:RegularExpressionValidator></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 328px; HEIGHT: 41px"><asp:DropDownList id="cboPartNumber" runat="server" DataSourceID="SqlDataSource3" OnSelectedIndexChanged="cboPartNumber_SelectedInde xChanged" AutoPostBack="True" DataTextField="partnumber" DataValueField="partnumber"></asp:DropDownList>&nbsp;<asp:Label id="lblSelDescription" runat="server" Font-Bold="True" ForeColor="Blue" Width="184px"></asp:Label>&nbsp;<BR /><asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" Width="176px" ControlToValidate="txtPartNumber" ErrorMessage="El número de parte es requerido." Font-Bold="False"></asp:RequiredFieldValidator></TD></TR><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 70px; HEIGHT: 39px; TEXT-ALIGN: right">Cantidad</TD><TD style="VERTICAL-ALIGN: top; WIDTH: 159px; HEIGHT: 39px"><asp:TextBox id="txtQuantity" runat="server" Width="48px" MaxLength="7"></asp:TextBox>&nbsp;<asp:RangeValidator id="RangeValidator1" runat="server" Width="96px" ControlToValidate="txtQuantity" ErrorMessage="Cantidad inválida" Type="Double" MinimumValue=".01" MaximumValue="1000000" Font-Bold="False"></asp:RangeValidator><BR /><asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" Width="144px" ControlToValidate="txtQuantity" ErrorMessage="Debe escribir una cantidad." Font-Bold="False"></asp:RequiredFieldValidator></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 328px; HEIGHT: 39px; TEXT-ALIGN: left">
&nbsp;<asp:Label id="lblPartNotFound" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Red" Width="271px" Text="No se encontró el número de parte especificado." Visible="False"></asp:Label></TD></TR><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 70px; HEIGHT: 36px; TEXT-ALIGN: right">
GT</TD><TD style="WIDTH: 159px; HEIGHT: 36px; vertical-align: top;">
<asp:TextBox ID="txtGT" runat="server" AutoPostBack="True" MaxLength="12" OnTextChanged="txtGT_TextChanged"></asp:TextBox><asp:RegularExpressionValidator
ID="GTValidator" runat="server" ControlToValidate="txtGT" Display="Dynamic" ErrorMessage="Máximo 12 caracteres."
ValidationExpression=".{0,12}" Width="120px" Font-Bold="False"></asp:RegularExpressionValidator></TD><TD style="WIDTH: 328px; HEIGHT: 36px"><asp:Button id="btnAddSupply" onclick="btnAddSupply_Click" runat="server" Text="Agregar"></asp:Button>&nbsp;
<asp:SqlDataSource id="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ReceivingDBConnectionString %>" SelectCommand="eK_IW_GetOrderPNInfo" SelectCommandType="StoredProcedure"><SelectParamet ers>
<asp:ControlParameter PropertyName="SelectedValue" Type="String" Name="OrderNumber" ControlID="cboOrders"></asp:ControlParameter>
<asp:SessionParameter Name="PlantID" SessionField="Planta" Type="String" />
</SelectParameters>
</asp:SqlDataSource></TD></TR></TBODY></TABLE><asp:GridView id="grdSupply" runat="server" ForeColor="Black" DataSourceID="SqlDataSource4" PageSize="5" AllowSorting="True" DataKeyNames="OrderNumber,PartNumber" AutoGenerateColumns="False" GridLines="Vertical" CellPadding="3" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" OnSelectedIndexChanged="grdSupply_SelectedIndexCha nged">
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Detalle" />
<asp:BoundField ReadOnly="True" DataField="OrderNumber" SortExpression="OrderNumber" HeaderText="Número de Orden"></asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="PartNumber" SortExpression="PartNumber" HeaderText="Número de Parte"></asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="description" SortExpression="description" HeaderText="Descripción"></asp:BoundField>
<asp:BoundField DataField="Quantity" SortExpression="Quantity" HeaderText="Cantidad Requerida"></asp:BoundField>
<asp:BoundField DataField="Supplied" SortExpression="Supplied" HeaderText="Cantidad Surtida"></asp:BoundField>
<asp:BoundField DataField="DateLastMaint" SortExpression="DateLastMaint" HeaderText="Fecha"></asp:BoundField>
</Columns>

<SelectedRowStyle BackColor="#804040" ForeColor="White" Font-Bold="True"></SelectedRowStyle>

<PagerStyle BackColor="Silver" ForeColor="Black" HorizontalAlign="Center"></PagerStyle>

<HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True"></HeaderStyle>

<AlternatingRowStyle BackColor="#E0E0E0"></AlternatingRowStyle>
</asp:GridView>
<br />
Detalle:<br />
<asp:GridView id="grdSupDetails" runat="server" ForeColor="Black" DataSourceID="sqlSupDetails" AutoGenerateDeleteButton="True" PageSize="5" AllowSorting="True" DataKeyNames="PartNumber,GTNumber,Quantity" AutoGenerateColumns="False" GridLines="Horizontal" CellPadding="4" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnSelectedIndexChanged="grdSupply_SelectedIndexCha nged" Width="376px">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="PartNumber" HeaderText="Número de Parte" SortExpression="PartNumber" />
<asp:BoundField DataField="GTNumber" HeaderText="GreenTag" SortExpression="GTNumber" />
<asp:BoundField DataField="Quantity" HeaderText="Cantidad" SortExpression="Quantity" />
</Columns>
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
&nbsp;
<asp:SqlDataSource id="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ReceivingDBConnectionString %>" SelectCommand="eK_IW_GetOrderInfoSupply" SelectCommandType="StoredProcedure" DeleteCommand="eK_IW_DelOrderSupply" DeleteCommandType="StoredProcedure"><DeleteParamet ers>
<asp:ControlParameter PropertyName="SelectedValue" Type="String" Name="OrderNumber" ControlID="grdSupply"></asp:ControlParameter>
<asp:ControlParameter PropertyName="SelectedValue" Type="String" Name="PartNumber" ControlID="grdSupply"></asp:ControlParameter>
<asp:SessionParameter Name="PlantID" SessionField="Planta" Type="String" />
<asp:SessionParameter Name="UserID" SessionField="username" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="cboOrders" Name="OrderNumber" PropertyName="SelectedValue"
Type="String" />
<asp:SessionParameter Name="PlantID" SessionField="Planta" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sqlSupDetails" runat="server" ConnectionString="<%$ ConnectionStrings:ReceivingDBConnectionString %>"
SelectCommand="eK_IW_GetOrderSuppDetails" SelectCommandType="StoredProcedure" DeleteCommand="eK_IW_DelOrderSupplyDetail" DeleteCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="grdSupply" Name="OrderNumber" PropertyName="SelectedDataKey.Values[0]" Type="String" />
<asp:ControlParameter ControlID="grdSupply" Name="PartNumber" PropertyName="SelectedDataKey.Values[1]" Type="String" />
<asp:SessionParameter Name="PlantID" SessionField="Planta" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="grdSupply" Name="OrderNumber" PropertyName="SelectedDataKey.Values[0]"
Type="String" />
<asp:SessionParameter Name="PlantID" SessionField="Planta" Type="String" />
<asp:ControlParameter ControlID="grdSupDetails" Name="PartNumber" PropertyName="SelectedDataKey.Values[0]"
Type="String" />
<asp:SessionParameter Name="UserID" SessionField="username" Type="String" />
<asp:ControlParameter ControlID="grdSupDetails" Name="GTNumber" PropertyName="SelectedDataKey.Values[1]"
Type="String" />
<asp:ControlParameter ControlID="grdSupDetails" Name="Quantity" PropertyName="SelectedDataKey.Values[2]"
Type="Double" />
</DeleteParameters>
</asp:SqlDataSource>
<BR /><asp:Button id="btnSupply" onclick="btnSupply_Click" runat="server" Text="Surtir Material"></asp:Button></asp:Panel>&nbsp;<BR /><BR /><BR /><asp:Panel style="DISPLAY: none; VERTICAL-ALIGN: middle; TEXT-ALIGN: center" id="pnlPopUpSupply" runat="server" Height="88px" Width="320px" BorderStyle="Double" BorderColor="Yellow" BackColor="White" Visible="true"><BR />¿Está seguro que desea surtir esta orden?<BR /><BR /><TABLE><TBODY><TR><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Button id="btnOkSupply" onclick="btnOkSupply_Click" runat="server" Text="Sí estoy seguro"></asp:Button></TD><TD style="WIDTH: 3px; HEIGHT: 26px"></TD><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Button id="btnCancelSupply" runat="server" Text="No, Regresar" UseSubmitBehavior="False" OnClick="btnCancelSupply_Click"></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender2" runat="server" TargetControlID="btnSupply" PopupControlID="pnlPopUpSupply" BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="btnCancelSupply">
</ajaxToolkit:ModalPopupExtender>&nbsp;&nbsp; <BR /><asp:Panel style="DISPLAY: none; VERTICAL-ALIGN: middle; TEXT-ALIGN: center" id="pnlPopUpCancel" runat="server" Height="88px" Width="320px" BorderStyle="Double" BorderColor="Red" BackColor="White" Visible="true" CssClass="modalPopup"><BR />¿Está seguro que desea cancelar la orden?<BR /><BR /><TABLE><TBODY><TR><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Button id="btnOkCancelOrder" onclick="btnOkCancelOrder_Click" runat="server" Text="Sí estoy seguro"></asp:Button></TD><TD style="WIDTH: 3px; HEIGHT: 26px"></TD><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Button id="btnCancelCancelOrder" runat="server" Text="No, Regresar" UseSubmitBehavior="False"></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender6" runat="server" TargetControlID="btnCancelOrder" PopupControlID="pnlPopUpCancel" BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="btnCancelCancelOrder">
</ajaxToolkit:ModalPopupExtender><BR /><BR /><asp:Timer id="timAutoUpdate" runat="server" Enabled="False" Interval="2500" OnTick="timAutoUpdate_Tick"></asp:Timer>
</contenttemplate>
</asp:UpdatePanel>
</asp:Content>
Mar 26 '08 #1
4 6006
chaarmann
785 Recognized Expert Contributor
So what's the error?
Which part doesn't work?
Where is the line inside your huge listing that does not work?

And please be nice to people who will help you for free and don't waste their time: please post only the part of the code that really matters.
Mar 26 '08 #2
pablorp80
3 New Member
As I said, the problem is that I can't find a way/method for set the cursor and the focus on a textbox (in this case txtGT).

I have tried this in the page_load event as well as in UpdatePanel1_Load and Page_LoadComplete:
[HTML] Page.SetFocus(txtGT)[/HTML]
never get it to work.

Also in the page_load event as well as in UpdatePanel1_Load and Page_LoadComplete:
[HTML] txtGT.Focus()[/HTML]
never get it to work.

Also lots of java scripts like:
[HTML]<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="infcontrol.aspx.vb" Inherits="orders_CutGroupAssign" title="eKanban Ordenes Especiales" %>
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="infcontrol.aspx.vb" Inherits="orders_CutGroupAssign" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<body onload="document.getElementById("txtGT").focus()"\ >
<asp:UpdateProgress ID="UpdPrgInf" runat="server" AssociatedUpdatePanelID="UpdatePanel1" ...[/HTML]
And it gots me this error: Syntax Error.
Looking at the page source, the error is originated somewhere here:
[HTML]<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00 $ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._upd ateControls(['tctl00$ContentPlaceHolder1$UpdatePanel1'], [], [], 90);
//]]>
</script>[/HTML]

Also this method: (which is supposed to keep the focus on the last element that had the focus)
Expand|Select|Wrap|Line Numbers
  1. Private Const SCRIPT_DOFOCUS As String = "window.setTimeout('DoFocus()', 1); " & _
  2.     "Function DoFocus() " & _
  3.     "{ " & _
  4.         "try { " & _
  5.             "document.getElementById('REQUEST_LASTFOCUS').focus(); " & _
  6.         "} catch (ex) {} " & _
  7.     "}"
  8. Private Sub HookOnFocus(ByVal CurrentControl As Control)
  9.         If TypeOf CurrentControl Is TextBox Then
  10.             CType(CurrentControl, WebControl).Attributes.Add("onfocus", "try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}")
  11.         End If
  12.         If CurrentControl.HasControls Then
  13.             For Each CurrentChildControl As Control In CurrentControl.Controls
  14.                 HookOnFocus(CurrentChildControl)
  15.             Next
  16.         End If
  17.     End Sub
  18.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  19.         If Not Page.IsPostBack Then
  20.             HookOnFocus(CType(Me.Page, Control))
  21.         End If
  22.         ScriptManager.RegisterStartupScript(Me, Me.GetType, "ScriptDoFocus", SCRIPT_DOFOCUS.Replace("REQUEST_LASTFOCUS", Request("__LASTFOCUS")), True)
  23.     End Sub
This dropped me the following error and never worked: Expected ';' (can't find where the ';' is expected by the way)

Also I have tried the one I've posted in the huge code list which looks for Forms[0] and then for the control, but I do not use any form so, it never worked also.

I am sorry about the huge listing. I guess just wanted to give all the details. I appreciate all of you are reading this, and are willing to give some help.


So what's the error?
Which part doesn't work?
Where is the line inside your huge listing that does not work?

And please be nice to people who will help you for free and don't waste their time: please post only the part of the code that really matters.
Mar 26 '08 #3
chaarmann
785 Recognized Expert Contributor
Your code snippets are not complete. What I mean with "list only relevant lines" is that you try to narrow down your problem by deleting all lines that have nothing to do with the problem. But I don't mean that you should leave out important lines which HAVE to do with the problem.

If you do this, then the solution comes by itself in most cases. What I try to teach is a principle how to solve problems. If a thirsty man asks me for water and I show him how to dig a well instead, I will help him more than if I give him a small glas of water and the next days he comes to ask me again and again.

But I can see your good spirit in trying, so I will give you the solution and will also discuss your tries and why they probably don't work.

for example here is a code snippet that works. It focuses on the second text box and I verified that it works in my browser (IE). Just open notepad, paste this code below and save it as test.html. Then open with your browser.

Expand|Select|Wrap|Line Numbers
  1. <input type=text id=t1>
  2. <input type=text id=t2>
  3. <input type=text id=t3>
  4. <script language=JavaScript>
  5. function setFocus()
  6. {
  7.     document.getElementById("t2").focus();
  8. }
  9. window.setTimeout("setFocus()", 1);
  10. </script>

ok,let's discuss your solutions:

As I said, the problem is that I can't find a way/method for set the cursor and the focus on a textbox (in this case txtGT).

I have tried this in the page_load event as well as in UpdatePanel1_Load and Page_LoadComplete:
[HTML] Page.SetFocus(txtGT)[/HTML]
never get it to work.

Also in the page_load event as well as in UpdatePanel1_Load and Page_LoadComplete:
[HTML] txtGT.Focus()[/HTML]
never get it to work.
where is "txtGT" defined? What is "Page" ? Is this VB or Javascript code? Code snippets should be consistent. that means if you define variables, you must also list the part of the code where they are declared..



Also lots of java scripts like:
[HTML]<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="infcontrol.aspx.vb" Inherits="orders_CutGroupAssign" title="eKanban Ordenes Especiales" %>
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="infcontrol.aspx.vb" Inherits="orders_CutGroupAssign" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<body onload="document.getElementById("txtGT").focus()"\ >
<asp:UpdateProgress ID="UpdPrgInf" runat="server" AssociatedUpdatePanelID="UpdatePanel1" ...[/HTML]
commands starting with "<%@" and ending with "%>" is serverside code.
You are mixing here serverside and clientside script. It is irrelevant for the problem HOW you generate the HTML on your server. Only the final HTML on your client counts for your problem. You should have chosen "View->Source" in your browser and posted this code instead.
Besides that, it should work if you write
Expand|Select|Wrap|Line Numbers
  1. <body onload="document.getElementById("txtGT").focus()">
The only difference between my example snippet and this way is that if elements are generated dynamic (I mean part of the HTML), and this dynamic part contains the <input type=text id=txtGT> element, then it is not available at onLoad-time and therefor would give an error. Whereas my function window.setTimeout() runs AFTER all other HTML elements have been created and therefore will not crash in such a case.
I can't see the element <input type=text id=txtGT> listed in your code snippet, therefore I don't know if it is there in your original code or not. I mean if you just simply forgot to list it in your code snippet or not. Or you listed it, but you gave it a different ID. or you forgot to close the bracket of the HTML tag. Or you mixed up lowercase and uppercase in your name, or you created it dynamically, or ...You see I must do a lot of guessing.That is what I meant with "list relevant lines".



And it gots me this error: Syntax Error.
Looking at the page source, the error is originated somewhere here:
[HTML]<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00 $ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._upd ateControls(['tctl00$ContentPlaceHolder1$UpdatePanel1'], [], [], 90);
//]]>
</script>[/HTML]
"Sys.WebForms.PageRequestManager" tells me that this kind of an error message is thrown when your system tries to generate the HTML on the serverside and has nothing to do with the problem, either. Most likely just some syntax errors in your ASP page or whatever. Because "CDATA" means DTD for XML (which elements are valid and which not) and has nothing to do with HTML.



Also this method: (which is supposed to keep the focus on the last element that had the focus)
Expand|Select|Wrap|Line Numbers
  1. Private Const SCRIPT_DOFOCUS As String = "window.setTimeout('DoFocus()', 1); " & _
  2.     "Function DoFocus() " & _
  3.     "{ " & _
  4.         "try { " & _
  5.             "document.getElementById('REQUEST_LASTFOCUS').focus(); " & _
  6.         "} catch (ex) {} " & _
  7.     "}"
  8. Private Sub HookOnFocus(ByVal CurrentControl As Control)
  9.         If TypeOf CurrentControl Is TextBox Then
  10.             CType(CurrentControl, WebControl).Attributes.Add("onfocus", "try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}")
  11.         End If
  12.         If CurrentControl.HasControls Then
  13.             For Each CurrentChildControl As Control In CurrentControl.Controls
  14.                 HookOnFocus(CurrentChildControl)
  15.             Next
  16.         End If
  17.     End Sub
  18.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  19.         If Not Page.IsPostBack Then
  20.             HookOnFocus(CType(Me.Page, Control))
  21.         End If
  22.         ScriptManager.RegisterStartupScript(Me, Me.GetType, "ScriptDoFocus", SCRIPT_DOFOCUS.Replace("REQUEST_LASTFOCUS", Request("__LASTFOCUS")), True)
  23.     End Sub
This dropped me the following error and never worked: Expected ';' (can't find where the ';' is expected by the way)
This is Visual basic script. It only runs in IE. If you use Firefox or any other browser, it won't run. Maybe this is your problem.
Only the script is given.But not the needed HTML where this script works on. Therefore this snipped is incomplete.
I can only guess again, that you may have not put the code for the text-input element with the Id="'REQUEST_LASTFOCUS'". I mean in your snippets above you gave it the ID="txtGT" but "txtGT" is nowwhere to find in this snippet. Only I can see
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('REQUEST_LASTFOCUS').focus();
Mar 26 '08 #4
pablorp80
3 New Member
Thanks Chaarman! Problem solved.
You have posted very interesting insights. However, your comments were not helpful in the problem solution. Instead, you have clarified lots of questions I had unanswered since long time ago. I appreciate it, seriously thanks!
Here is the solution:
In the page_load event added some code...
Expand|Select|Wrap|Line Numbers
  1.  
  2. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  3.         Dim textAnotacion As TextBox = pnlSupply.FindControl("txtGT")
  4.         Dim scriptManager As ScriptManager = scriptManager.GetCurrent(Me.Page)
  5.         scriptManager.SetFocus(textAnotacion)
  6. End Sub
  7.  
The explanation is that, I must use the scriptmanager.setfocus method instead of the others I have tried.

The original solution (in spanish) can be found at:
http://geeks.ms/blogs/lruiz/archive/2007/12/26/poner-el-foco-en-un-textbox-que-est-225-n-dentro-de-un-updatepanel-cuando-se-produce-un-postback-as-237-ncrono.aspx

Thank you very much Chaarman!
Mar 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: RBM007 | last post by:
Hello, I have created some pages in the (old) Atlas pages and migrated to AJAX version. After the update I noticed that any page containing ASP.NET AJAX won't compile anymore. Even if the same...
1
by: =?Utf-8?B?TGFycnkgRXBu?= | last post by:
I have an app using Ajax. The scriptmanager is within the form that is within the master page. I also have web user controls that are doing partial rendering and are "borrowing" or "inheriting"...
2
by: Rissoman | last post by:
I have two user controls on a master page. I can easily bubble up an event on usercontrol 1 from a click event to the page.aspx, than then calls a method on the masterpage, but this causes the...
2
by: nicknack | last post by:
Hello. A little tricky situation: I have a master page. Inside that master page I have A div (With overflow:scroll) that contain an ajax updatePanel. Inside that updatePanel I have a tree. The...
11
by: sheldonlg | last post by:
I have a problem with not seeing the current focus while in a particular screen in a my app. The focus does not show for a type=text or textarea. I have tried to reproduce this problem in a test...
8
by: Mel | last post by:
I have several text boxes and drop-down lists in an AJAX Update Panel. All user inputs have the Postback property set to True. After I type something in the first input entry and press the "Tab"...
10
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi, Trying to create a master page that holds a menu, and the menu switches between pages in the site. 2 problem arrosed: a. When I navigate from page to page (all AJAX Web Forms, with the...
4
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody...
1
by: Drelus | last post by:
I'm using an Ajax call to open a search box in the page and I want the focus to go to the box automatically. So, in the httpObject.responseText, I tried sending the following in addition to the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.