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.mast er" AutoEventWireup ="false" CodeFile="infco ntrol.aspx.vb" Inherits="order s_CutGroupAssig n" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1" Runat="Server">
<script language=javasc ript>
function setFocus(ctl) {
if (document.forms[0][ctl] != null)
document.forms[0][ctl].focus();
}
setFocus("txtGT ")
</script>
<asp:UpdateProg ress ID="UpdPrgInf" runat="server" AssociatedUpdat ePanelID="Updat ePanel1"
DisplayAfter="1 ">
<ProgressTempla te>
<img src="../images/wait.gif" />
</ProgressTemplat e>
</asp:UpdateProgr ess>
<asp:UpdatePane l id="UpdatePanel 1" runat="server">
<contenttemplat e>
<asp:Label ID="lblTitleApp " runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#FF8 000"
Text="Control de Infladores"></asp:Label><br />
<asp:SqlDataSou rce id="SqlDataSour ce2" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:ReceivingDBC onnectionString %>" SelectCommand=" eK_IW_GetOpenOr ders" SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:SessionPar ameter DefaultValue="I RS" Name="PlantID" SessionField="P lanta" Type="String" />
</SelectParameter s>
</asp:SqlDataSour ce> <asp:Panel id="pnlStatus" runat="server" Height="30px" Width="645px" BackColor="#E0E 0E0"><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:DropDownLi st id="cboOrders" runat="server" DataSourceID="S qlDataSource2" OnSelectedIndex Changed="cboOrd ers_SelectedInd exChanged" AutoPostBack="T rue" DataTextField=" Ordernumber" DataValueField= "Ordernumbe r"></asp:DropDownLis t>
<asp:TextBox id="txtOrderSca n" runat="server" AutoPostBack="T rue" OnTextChanged=" txtOrderScan_Te xtChanged" Width="125px"></asp:TextBox></TD><TD style="HEIGHT: 18px; width: 78px; text-align: left;"> <asp:Label id="lblInvalidO rder" 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="btnCancelOr der" runat="server" Text="Cancelar Orden" Visible="False" OnClick="btnCan celOrder_Click" ></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <BR /><asp:Label id="lblStatus" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Roya lBlue" Width="568px" Text="Status Orden" Visible="False" ></asp:Label><BR />
<asp:Panel id="pnlSupply" runat="server" Width="650px">< SPAN style="FONT-SIZE: 10pt">Especifiq ue el numero de parte del material que va a surtir y la cantidad para esta orden:<BR /> </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:Text Box id="txtPartNumb er" runat="server" MaxLength="25"> </asp:TextBox><BR /><asp:RegularEx pressionValidat or id="RegularExpr essionValidator 2" runat="server" Width="120px" ControlToValida te="txtPartNumb er" ErrorMessage="M áximo 25 caracteres." ValidationExpre ssion=".{0,25}" Display="Dynami c" Font-Bold="False"></asp:RegularExpr essionValidator ></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 328px; HEIGHT: 41px"><asp:Drop DownList id="cboPartNumb er" runat="server" DataSourceID="S qlDataSource3" OnSelectedIndex Changed="cboPar tNumber_Selecte dIndexChanged" AutoPostBack="T rue" DataTextField=" partnumber" DataValueField= "partnumber "></asp:DropDownLis t> <asp:La bel id="lblSelDescr iption" runat="server" Font-Bold="True" ForeColor="Blue " Width="184px"></asp:Label>  ;<BR /><asp:RequiredF ieldValidator id="RequiredFie ldValidator3" runat="server" Width="176px" ControlToValida te="txtPartNumb er" ErrorMessage="E l número de parte es requerido." Font-Bold="False"></asp:RequiredFie ldValidator></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:Text Box id="txtQuantity " runat="server" Width="48px" MaxLength="7"></asp:TextBox>&nb sp;<asp:RangeVa lidator id="RangeValida tor1" runat="server" Width="96px" ControlToValida te="txtQuantity " ErrorMessage="C antidad inválida" Type="Double" MinimumValue=". 01" MaximumValue="1 000000" Font-Bold="False"></asp:RangeValida tor><BR /><asp:RequiredF ieldValidator id="RequiredFie ldValidator5" runat="server" Width="144px" ControlToValida te="txtQuantity " ErrorMessage="D ebe escribir una cantidad." Font-Bold="False"></asp:RequiredFie ldValidator></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 328px; HEIGHT: 39px; TEXT-ALIGN: left">
<asp:Labe l id="lblPartNotF ound" 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="T rue" MaxLength="12" OnTextChanged=" txtGT_TextChang ed"></asp:TextBox><as p:RegularExpres sionValidator
ID="GTValidator " runat="server" ControlToValida te="txtGT" Display="Dynami c" ErrorMessage="M áximo 12 caracteres."
ValidationExpre ssion=".{0,12}" Width="120px" Font-Bold="False"></asp:RegularExpr essionValidator ></TD><TD style="WIDTH: 328px; HEIGHT: 36px"><asp:Butt on id="btnAddSuppl y" onclick="btnAdd Supply_Click" runat="server" Text="Agregar"> </asp:Button>&nbs p;
<asp:SqlDataSou rce id="SqlDataSour ce3" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:ReceivingDBC onnectionString %>" SelectCommand=" eK_IW_GetOrderP NInfo" SelectCommandTy pe="StoredProce dure"><SelectPa rameters>
<asp:ControlPar ameter PropertyName="S electedValue" Type="String" Name="OrderNumb er" ControlID="cboO rders"></asp:ControlPara meter>
<asp:SessionPar ameter Name="PlantID" SessionField="P lanta" Type="String" />
</SelectParameter s>
</asp:SqlDataSour ce></TD></TR></TBODY></TABLE><asp:Grid View id="grdSupply" runat="server" ForeColor="Blac k" DataSourceID="S qlDataSource4" PageSize="5" AllowSorting="T rue" DataKeyNames="O rderNumber,Part Number" AutoGenerateCol umns="False" GridLines="Vert ical" CellPadding="3" BackColor="Whit e" BorderColor="#9 99999" BorderStyle="So lid" BorderWidth="1p x" OnSelectedIndex Changed="grdSup ply_SelectedInd exChanged">
<FooterStyle BackColor="#CCC CCC"></FooterStyle>
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" SelectText="Det alle" />
<asp:BoundFie ld ReadOnly="True" DataField="Orde rNumber" SortExpression= "OrderNumbe r" HeaderText="Núm ero de Orden"></asp:BoundField>
<asp:BoundFie ld ReadOnly="True" DataField="Part Number" SortExpression= "PartNumber " HeaderText="Núm ero de Parte"></asp:BoundField>
<asp:BoundFie ld ReadOnly="True" DataField="desc ription" SortExpression= "descriptio n" HeaderText="Des cripción"></asp:BoundField>
<asp:BoundFie ld DataField="Quan tity" SortExpression= "Quantity" HeaderText="Can tidad Requerida"></asp:BoundField>
<asp:BoundFie ld DataField="Supp lied" SortExpression= "Supplied" HeaderText="Can tidad Surtida"></asp:BoundField>
<asp:BoundFie ld DataField="Date LastMaint" SortExpression= "DateLastMa int" HeaderText="Fec ha"></asp:BoundField>
</Columns>
<SelectedRowSty le BackColor="#804 040" ForeColor="Whit e" Font-Bold="True"></SelectedRowStyl e>
<PagerStyle BackColor="Silv er" ForeColor="Blac k" HorizontalAlign ="Center"></PagerStyle>
<HeaderStyle BackColor="Blac k" ForeColor="Whit e" Font-Bold="True"></HeaderStyle>
<AlternatingRow Style BackColor="#E0E 0E0"></AlternatingRowS tyle>
</asp:GridView>
<br />
Detalle:<br />
<asp:GridView id="grdSupDetai ls" runat="server" ForeColor="Blac k" DataSourceID="s qlSupDetails" AutoGenerateDel eteButton="True " PageSize="5" AllowSorting="T rue" DataKeyNames="P artNumber,GTNum ber,Quantity" AutoGenerateCol umns="False" GridLines="Hori zontal" CellPadding="4" BackColor="Whit e" BorderColor="#C CCCCC" BorderStyle="No ne" BorderWidth="1p x" OnSelectedIndex Changed="grdSup ply_SelectedInd exChanged" Width="376px">
<FooterStyle BackColor="#CCC C99" ForeColor="Blac k" />
<Columns>
<asp:BoundFie ld DataField="Part Number" HeaderText="Núm ero de Parte" SortExpression= "PartNumber " />
<asp:BoundFie ld DataField="GTNu mber" HeaderText="Gre enTag" SortExpression= "GTNumber" />
<asp:BoundFie ld DataField="Quan tity" HeaderText="Can tidad" SortExpression= "Quantity" />
</Columns>
<SelectedRowSty le BackColor="#CC3 333" Font-Bold="True" ForeColor="Whit e" />
<PagerStyle BackColor="Whit e" ForeColor="Blac k" HorizontalAlign ="Right" />
<HeaderStyle BackColor="#333 333" Font-Bold="True" ForeColor="Whit e" />
</asp:GridView>
<asp:SqlDataSou rce id="SqlDataSour ce4" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:ReceivingDBC onnectionString %>" SelectCommand=" eK_IW_GetOrderI nfoSupply" SelectCommandTy pe="StoredProce dure" DeleteCommand=" eK_IW_DelOrderS upply" DeleteCommandTy pe="StoredProce dure"><DeletePa rameters>
<asp:ControlPar ameter PropertyName="S electedValue" Type="String" Name="OrderNumb er" ControlID="grdS upply"></asp:ControlPara meter>
<asp:ControlPar ameter PropertyName="S electedValue" Type="String" Name="PartNumbe r" ControlID="grdS upply"></asp:ControlPara meter>
<asp:SessionPar ameter Name="PlantID" SessionField="P lanta" Type="String" />
<asp:SessionPar ameter Name="UserID" SessionField="u sername" Type="String" />
</DeleteParameter s>
<SelectParamete rs>
<asp:ControlPar ameter ControlID="cboO rders" Name="OrderNumb er" PropertyName="S electedValue"
Type="String" />
<asp:SessionPar ameter Name="PlantID" SessionField="P lanta" Type="String" />
</SelectParameter s>
</asp:SqlDataSour ce>
<asp:SqlDataSou rce ID="sqlSupDetai ls" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:ReceivingDBC onnectionString %>"
SelectCommand=" eK_IW_GetOrderS uppDetails" SelectCommandTy pe="StoredProce dure" DeleteCommand=" eK_IW_DelOrderS upplyDetail" DeleteCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="grdS upply" Name="OrderNumb er" PropertyName="S electedDataKey. Values[0]" Type="String" />
<asp:ControlPar ameter ControlID="grdS upply" Name="PartNumbe r" PropertyName="S electedDataKey. Values[1]" Type="String" />
<asp:SessionPar ameter Name="PlantID" SessionField="P lanta" Type="String" />
</SelectParameter s>
<DeleteParamete rs>
<asp:ControlPar ameter ControlID="grdS upply" Name="OrderNumb er" PropertyName="S electedDataKey. Values[0]"
Type="String" />
<asp:SessionPar ameter Name="PlantID" SessionField="P lanta" Type="String" />
<asp:ControlPar ameter ControlID="grdS upDetails" Name="PartNumbe r" PropertyName="S electedDataKey. Values[0]"
Type="String" />
<asp:SessionPar ameter Name="UserID" SessionField="u sername" Type="String" />
<asp:ControlPar ameter ControlID="grdS upDetails" Name="GTNumber" PropertyName="S electedDataKey. Values[1]"
Type="String" />
<asp:ControlPar ameter ControlID="grdS upDetails" Name="Quantity" PropertyName="S electedDataKey. Values[2]"
Type="Double" />
</DeleteParameter s>
</asp:SqlDataSour ce>
<BR /><asp:Button id="btnSupply" onclick="btnSup ply_Click" runat="server" Text="Surtir Material"></asp:Button></asp:Panel>  ;<BR /><BR /><BR /><asp:Panel style="DISPLAY: none; VERTICAL-ALIGN: middle; TEXT-ALIGN: center" id="pnlPopUpSup ply" runat="server" Height="88px" Width="320px" BorderStyle="Do uble" BorderColor="Ye llow" BackColor="Whit e" Visible="true"> <BR />¿Está seguro que desea surtir esta orden?<BR /><BR /><TABLE><TBODY> <TR><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Butt on id="btnOkSupply " onclick="btnOkS upply_Click" runat="server" Text="Sí estoy seguro"></asp:Button></TD><TD style="WIDTH: 3px; HEIGHT: 26px"></TD><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Butt on id="btnCancelSu pply" runat="server" Text="No, Regresar" UseSubmitBehavi or="False" OnClick="btnCan celSupply_Click "></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <ajaxToolkit:Mo dalPopupExtende r id="ModalPopupE xtender2" runat="server" TargetControlID ="btnSupply" PopupControlID= "pnlPopUpSupply " BackgroundCssCl ass="modalBackg round" DropShadow="tru e" CancelControlID ="btnCancelSupp ly">
</ajaxToolkit:Mod alPopupExtender > <BR /><asp:Panel style="DISPLAY: none; VERTICAL-ALIGN: middle; TEXT-ALIGN: center" id="pnlPopUpCan cel" runat="server" Height="88px" Width="320px" BorderStyle="Do uble" BorderColor="Re d" BackColor="Whit e" Visible="true" CssClass="modal Popup"><BR />¿Está seguro que desea cancelar la orden?<BR /><BR /><TABLE><TBODY> <TR><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Butt on id="btnOkCancel Order" onclick="btnOkC ancelOrder_Clic k" runat="server" Text="Sí estoy seguro"></asp:Button></TD><TD style="WIDTH: 3px; HEIGHT: 26px"></TD><TD style="WIDTH: 3px; HEIGHT: 26px"><asp:Butt on id="btnCancelCa ncelOrder" runat="server" Text="No, Regresar" UseSubmitBehavi or="False"></asp:Button></TD></TR></TBODY></TABLE></asp:Panel> <ajaxToolkit:Mo dalPopupExtende r id="ModalPopupE xtender6" runat="server" TargetControlID ="btnCancelOrde r" PopupControlID= "pnlPopUpCancel " BackgroundCssCl ass="modalBackg round" DropShadow="tru e" CancelControlID ="btnCancelCanc elOrder">
</ajaxToolkit:Mod alPopupExtender ><BR /><BR /><asp:Timer id="timAutoUpda te" runat="server" Enabled="False" Interval="2500" OnTick="timAuto Update_Tick"></asp:Timer>
</contenttemplate >
</asp:UpdatePanel >
</asp:Content>
4 6051
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.
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_Lo ad and Page_LoadComple te:
[HTML] Page.SetFocus(t xtGT)[/HTML]
never get it to work.
Also in the page_load event as well as in UpdatePanel1_Lo ad and Page_LoadComple te:
[HTML] txtGT.Focus()[/HTML]
never get it to work.
Also lots of java scripts like:
[HTML]<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" AutoEventWireup ="false" CodeFile="infco ntrol.aspx.vb" Inherits="order s_CutGroupAssig n" title="eKanban Ordenes Especiales" %>
<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" AutoEventWireup ="false" CodeFile="infco ntrol.aspx.vb" Inherits="order s_CutGroupAssig n" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1" Runat="Server"> <body onload="documen t.getElementByI d("txtGT").focu s()"\>
<asp:UpdateProg ress ID="UpdPrgInf" runat="server" AssociatedUpdat ePanelID="Updat ePanel1" ...[/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.Pa geRequestManage r._initialize(' ctl00$ScriptMan ager1', document.getEle mentById('aspne tForm'));
Sys.WebForms.Pa geRequestManage r.getInstance() ._updateControl s(['tctl00$Content PlaceHolder1$Up datePanel1'], [], [], 90);
//]]>
</script>[/HTML]
Also this method: (which is supposed to keep the focus on the last element that had the focus) - Private Const SCRIPT_DOFOCUS As String = "window.setTimeout('DoFocus()', 1); " & _
-
"Function DoFocus() " & _
-
"{ " & _
-
"try { " & _
-
"document.getElementById('REQUEST_LASTFOCUS').focus(); " & _
-
"} catch (ex) {} " & _
-
"}"
-
Private Sub HookOnFocus(ByVal CurrentControl As Control)
-
If TypeOf CurrentControl Is TextBox Then
-
CType(CurrentControl, WebControl).Attributes.Add("onfocus", "try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}")
-
End If
-
If CurrentControl.HasControls Then
-
For Each CurrentChildControl As Control In CurrentControl.Controls
-
HookOnFocus(CurrentChildControl)
-
Next
-
End If
-
End Sub
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
If Not Page.IsPostBack Then
-
HookOnFocus(CType(Me.Page, Control))
-
End If
-
ScriptManager.RegisterStartupScript(Me, Me.GetType, "ScriptDoFocus", SCRIPT_DOFOCUS.Replace("REQUEST_LASTFOCUS", Request("__LASTFOCUS")), True)
-
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.
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. - <input type=text id=t1>
-
<input type=text id=t2>
-
<input type=text id=t3>
-
<script language=JavaScript>
-
function setFocus()
-
{
-
document.getElementById("t2").focus();
-
}
-
window.setTimeout("setFocus()", 1);
-
</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_Lo ad and Page_LoadComple te:
[HTML] Page.SetFocus(t xtGT)[/HTML]
never get it to work.
Also in the page_load event as well as in UpdatePanel1_Lo ad and Page_LoadComple te:
[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.mast er" AutoEventWireup ="false" CodeFile="infco ntrol.aspx.vb" Inherits="order s_CutGroupAssig n" title="eKanban Ordenes Especiales" %>
<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" AutoEventWireup ="false" CodeFile="infco ntrol.aspx.vb" Inherits="order s_CutGroupAssig n" title="eKanban Ordenes Especiales" %>
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1" Runat="Server"> <body onload="documen t.getElementByI d("txtGT").focu s()"\>
<asp:UpdateProg ress ID="UpdPrgInf" runat="server" AssociatedUpdat ePanelID="Updat ePanel1" ...[/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 - <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.setTimeo ut() 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.Pa geRequestManage r._initialize(' ctl00$ScriptMan ager1', document.getEle mentById('aspne tForm'));
Sys.WebForms.Pa geRequestManage r.getInstance() ._updateControl s(['tctl00$Content PlaceHolder1$Up datePanel1'], [], [], 90);
//]]>
</script>[/HTML]
"Sys.WebForms.P ageRequestManag er" 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) - Private Const SCRIPT_DOFOCUS As String = "window.setTimeout('DoFocus()', 1); " & _
-
"Function DoFocus() " & _
-
"{ " & _
-
"try { " & _
-
"document.getElementById('REQUEST_LASTFOCUS').focus(); " & _
-
"} catch (ex) {} " & _
-
"}"
-
Private Sub HookOnFocus(ByVal CurrentControl As Control)
-
If TypeOf CurrentControl Is TextBox Then
-
CType(CurrentControl, WebControl).Attributes.Add("onfocus", "try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}")
-
End If
-
If CurrentControl.HasControls Then
-
For Each CurrentChildControl As Control In CurrentControl.Controls
-
HookOnFocus(CurrentChildControl)
-
Next
-
End If
-
End Sub
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
If Not Page.IsPostBack Then
-
HookOnFocus(CType(Me.Page, Control))
-
End If
-
ScriptManager.RegisterStartupScript(Me, Me.GetType, "ScriptDoFocus", SCRIPT_DOFOCUS.Replace("REQUEST_LASTFOCUS", Request("__LASTFOCUS")), True)
-
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_LA STFOCUS'". 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 - document.getElementById('REQUEST_LASTFOCUS').focus();
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... -
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Dim textAnotacion As TextBox = pnlSupply.FindControl("txtGT")
-
Dim scriptManager As ScriptManager = scriptManager.GetCurrent(Me.Page)
-
scriptManager.SetFocus(textAnotacion)
-
End Sub
-
The explanation is that, I must use the scriptmanager.s etfocus 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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 tags and properties are
used in a page without a masterpage.
Does anyone shares this exprerience with me or does anyone knows an
answer?
For the time being, I copy-pased the headings in my masterpage to the
clield pages.
|
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" the scriptmanager from the
master page. Heck, when they're rendered, the scriptmanager is on all the
pages and it works.
However, in the VS2005 designer, I constantly see "Can't render image"
errors, and it's nearly impossible to effectively use...
|
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 screen to do a
postbacka nd full load. What I'm doing is i have a button on one user
control that when clicked it will dynamically load a usercontrol into
a placeholder on the masterpage. I know that if I were to put
everything into an update...
|
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 problem is That if I scroll down the tree and then select a node.
The tree jump back to the top.
Because I'm inside a masterpage I don't have the
"maintainScrollPositionOnPostBack".
|
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 application,
but have not been successful is doing that.
The actual app has a screen which is displayed on a template and the
contents are the return from an AJAX call. In that content there is a
hidden block. Clicking on a button in the...
| |
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" key how
can I set the focus to the next box after the postback? Please help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
|
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 Master
pages as their master...) the entire page is refreshed - also the menu which
belongs to the master, how can I fix it - so only the inside content will be
refreshed ?
|
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 know if
it is possible to make such focus? Thanks!
Bill
|
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 search box markup:
<script type="text/javascript">
document.getElementById('Message').focus();
</script>
and, after writing the response using innerHTML, the originating Ajax function calls an eval function to enable the JavaScript, the critical...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |