469,320 Members | 2,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

Focus on a text box / AJAX and MasterPage

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 5586
chaarmann
785 Expert 512MB
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
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 Expert 512MB
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
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

Post your reply

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

Similar topics

1 post views Thread by =?Utf-8?B?TGFycnkgRXBu?= | last post: by
2 posts views Thread by nicknack | last post: by
11 posts views Thread by sheldonlg | last post: by
8 posts views Thread by Mel | last post: by
10 posts views Thread by =?Utf-8?B?RGFuaQ==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.