Well I wasn't to sure if post this on the javascript forum or here, but since is an error that probably I got because something related to my ASP.Net code I decided to posted here.
Ok my problem is that I need to set focus on a textbox everytime the page is loaded. Maybe you already thinking what I thought at first, that with a textbox.setFocus() that will do it. Nop this is .Net Framework 1.1 and textbox.setFocus() didn't exist back then. So I did the other simple thing add a javascript on body onload="document.getElementById(<%= txtPCode.ClientID %>).focus(). It works on page load but not in postback. I really have try a couple of other things like adding this function in the .vb -
-
Private Sub SetFocus(ByVal ClientID As String)
-
Dim Script As New System.Text.StringBuilder
-
'Dim ClientID As String = FocusControl.ClientID
-
With Script
-
.Append("<script language='javascript'>")
-
.Append("document.getElementById('")
-
.Append(ClientID)
-
.Append("').focus();")
-
.Append("</script>")
-
End With
-
RegisterStartupScript("setFocus", Script.ToString())
-
End Sub
-
and calling it in from the Page_Load like this SetFocus(textbox.ClientID).
Anyway nothing of this have work to set the focus of the textbox on the page post back.
Anyone have another idea?
Thanks,
Erick
24 3673
Well I wasn't to sure if post this on the javascript forum or here, but since is an error that probably I got because something related to my ASP.Net code I decided to posted here.
Ok my problem is that I need to set focus on a textbox everytime the page is loaded. Maybe you already thinking what I thought at first, that with a textbox.setFocus() that will do it. Nop this is .Net Framework 1.1 and textbox.setFocus() didn't exist back then. So I did the other simple thing add a javascript on body onload="document.getElementById(<%= txtPCode.ClientID %>).focus(). It works on page load but not in postback. I really have try a couple of other things like adding this function in the .vb -
-
Private Sub SetFocus(ByVal ClientID As String)
-
Dim Script As New System.Text.StringBuilder
-
'Dim ClientID As String = FocusControl.ClientID
-
With Script
-
.Append("<script language='javascript'>")
-
.Append("document.getElementById('")
-
.Append(ClientID)
-
.Append("').focus();")
-
.Append("</script>")
-
End With
-
RegisterStartupScript("setFocus", Script.ToString())
-
End Sub
-
and calling it in from the Page_Load like this SetFocus(textbox.ClientID).
Anyway nothing of this have work to set the focus of the textbox on the page post back.
Anyone have another idea?
Thanks,
Erick
You're on the right track Erick.
I have solved this same problem in the past but it is a matter of where you place your JavaScript call... You need to set the focus in the OnLoad in your <body> tag. This means that you have to place your JavaScript in the <head> section of your page.
You'll need something like: -
<script language=javascript type="text/javascript">
-
onload = function()
-
{ /*get all input elements on page */
-
var allinputelements=document.getElementsByTagName('input');
-
var len= A.length;
-
/* setting the focus to the first input element that allows focus*/
-
-
for(var i = 0; i < len; i++)
-
{
-
try{
-
allinputelements[i].focus();
-
break;
-
}
-
catch(error)
-
{/*focus wasn't set*/}
-
}
-
-
}
-
</script>
-
please note that my javascript function is just an example and may not actually work
Instead of setting the focus on the first control that allows focus, you could register a hidden field with the name of the control in your Server Side code and set the focus to that field using the GetElementByID('nameOfYourControlStoredInTheHidden FieldYouRegistered').
Keep trying :)
You'll get it!
Just remember that your JS must be declared in the Head section of your web page in order for it to work on load :)
-Frinny
Well I wasn't to sure if post this on the javascript forum or here, but since is an error that probably I got because something related to my ASP.Net code I decided to posted here.
Ok my problem is that I need to set focus on a textbox everytime the page is loaded. Maybe you already thinking what I thought at first, that with a textbox.setFocus() that will do it. Nop this is .Net Framework 1.1 and textbox.setFocus() didn't exist back then. So I did the other simple thing add a javascript on body onload="document.getElementById(<%= txtPCode.ClientID %>).focus(). It works on page load but not in postback. I really have try a couple of other things like adding this function in the .vb -
-
Private Sub SetFocus(ByVal ClientID As String)
-
Dim Script As New System.Text.StringBuilder
-
'Dim ClientID As String = FocusControl.ClientID
-
With Script
-
.Append("<script language='javascript'>")
-
.Append("document.getElementById('")
-
.Append(ClientID)
-
.Append("').focus();")
-
.Append("</script>")
-
End With
-
RegisterStartupScript("setFocus", Script.ToString())
-
End Sub
-
and calling it in from the Page_Load like this SetFocus(textbox.ClientID).
Anyway nothing of this have work to set the focus of the textbox on the page post back.
Anyone have another idea?
Thanks,
Erick
This looks a lot like what you have already tried but this code works for me. Put this in your page_load event. - Page.RegisterStartupScript("SetFocus", ("<script>document.getElementById('" + (txtfirstName.ClientID + "').focus();</script>")))
Nathan
Thanks, but neither worked.
I don't know what else to try.
Thanks, but neither worked.
I don't know what else to try.
Please post your exact code so that we can see what you have done.
I don't know why it wouldn't have worked for you.
We'll get you through this :)
-Frinny
You could try viewing the source on say a google page and seeing what they do?
I did mention that the code I posted wasn't working 100%.
If you had copied and pasted into your code it would not have worked.
Did you look at the error that was generated by this JavaScript code?
This should probably correct the mistake: -
<script language=javascript type="text/javascript">
-
onload = function()
-
{ /*get all input elements on page */
-
var allinputelements=document.getElementsByTagName('in put');
-
var len= allinputelements.length;
-
/* setting the focus to the first input element that allows focus*/
-
for(var i = 0; i < len; i++)
-
{
-
try{
-
allinputelements[i].focus();
-
break;
-
}
-
catch(error)
-
{/*focus wasn't set*/}
-
-
}
-
}
-
</script>
-
Can you see what I changed?
I still haven't tested this but I'm pretty sure it'll work now.
You're still going to have to put it in the <head> section of your HTML.
-Frinny
I am a little confused. Do all the html elements not still have the .focus() in javascript? -
<body onload="myobj.focus()">
-
That seems like it should work regardless of postback behavior?
(Unless of course your making behind the scenes calls ala AJAX) http://javascript.internet.com/page-...us-onload.html
I am a little confused. Do all the html elements not still have the .focus() in javascript? -
<body onload="myobj.focus()">
-
That seems like it should work regardless of postback behavior?
(Unless of course your making behind the scenes calls ala AJAX) http://javascript.internet.com/page-...us-onload.html
Some objects (like hidden fields) don't let you set the focus on them though. That's why there's a Try/Catch block in the loop through all the input elements in my JavaScript function.
But you're right, it should work regardless of the postback behaviour when used like this (with the exception to asynchronous requests to the server using partial page update of course).
Why all this talk of hidden textboxes?
He knows the name of the textbox.
It's not hidden.
mynothiddentextbox.focus()
(Assuming one uses the NAME property, otherwise you'll need the getElementById())
Why all this talk of hidden textboxes?
He knows the name of the textbox.
It's not hidden.
mynothiddentextbox.focus()
(Assuming one uses the NAME property, otherwise you'll need the getElementById())
Hmm I had to read the question again.
Maybe this person's using an Ajax call to do a partial page update?
I'm tired of looking for the problem. I didn't create the code, it was the guy before me so maybe he have something that it's not allowing this to work. Here is the code if anyone can figured it out. -
Imports System.Data.Odbc
-
-
Namespace ASPNET.StarterKit.Portal
-
-
Public Class ProductLookUpPage
-
'Inherits System.Web.UI.Page
-
Inherits ASPNET.StarterKit.Portal.PortalPage
-
Protected WithEvents lnkReturn0 As System.Web.UI.WebControls.LinkButton
-
Protected WithEvents lnkReturn1 As System.Web.UI.WebControls.LinkButton
-
-
Protected WithEvents phBanner As System.Web.UI.WebControls.PlaceHolder
-
Protected WithEvents lblTitle As System.Web.UI.WebControls.Label
-
Protected WithEvents cmdLocate As System.Web.UI.WebControls.Button
-
Protected WithEvents txtPCode As System.Web.UI.WebControls.TextBox
-
Protected WithEvents vsPCode As System.Web.UI.WebControls.ValidationSummary
-
Protected WithEvents rfvPCode As System.Web.UI.WebControls.RequiredFieldValidator
-
Protected WithEvents revPCode As System.Web.UI.WebControls.RegularExpressionValidator
-
Protected WithEvents cvPCode As System.Web.UI.WebControls.CustomValidator
-
Protected WithEvents dlProductNumbers As System.Web.UI.WebControls.DataList
-
Protected WithEvents lblPCodeValue As System.Web.UI.WebControls.Label
-
Protected WithEvents lblDescValue As System.Web.UI.WebControls.Label
-
Protected WithEvents lblSizeValue As System.Web.UI.WebControls.Label
-
Protected WithEvents lblWHHead As System.Web.UI.WebControls.Label
-
Protected WithEvents lblWHQty As System.Web.UI.WebControls.Label
-
Protected WithEvents lblStoreHead As System.Web.UI.WebControls.Label
-
Protected WithEvents lblStoreQty As System.Web.UI.WebControls.Label
-
Protected WithEvents btnPriceIt As System.Web.UI.HtmlControls.HtmlInputButton
-
Protected WithEvents spnContent As System.Web.UI.HtmlControls.HtmlGenericControl
-
-
#Region " Web Form Designer Generated Code "
-
-
'This call is required by the Web Form Designer.
-
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
-
End Sub
-
-
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
-
'CODEGEN: This method call is required by the Web Form Designer
-
'Do not modify it using the code editor.
-
InitializeComponent()
-
End Sub
-
-
#End Region
-
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Trace.Warn("Default.aspx.vb", "Called Page_Load()")
-
'DO NOT remove this line
-
'This is what loads the banner into the top
-
phBanner.Controls.Add(Page.LoadControl("../../../DesktopPortalBanner.ascx"))
-
-
'07/20/07
-
SetFocus(txtPCode.ClientID)
-
-
'Counteract the DHTML onclick event assigned to the Look-Up Command Button
-
txtPCode.Attributes.Add("onfocus", "document.forms(0).cmdLookup.disabled = false;")
-
-
' 03/16/05 WNS Added PriceIt
-
btnPriceIt.Visible = False
-
Page.RegisterHiddenField("__EVENTTARGET", cmdLocate.ClientID)
-
If Page.IsPostBack = False Then
-
' Store URL Referrer to return to portal
-
Try
-
ViewState("UrlReferrer") = Request.UrlReferrer.ToString()
-
Catch ex As Exception
-
Dim clsApp As New CustomAppSettings
-
ViewState("UrlReferrer") = clsApp.GetAppSetting("StoreTab_Url")
-
End Try
-
-
Page.RegisterHiddenField("__EVENTTARGET", cmdLocate.ClientID)
-
-
If Request.Params("pcode") <> "" Then
-
Dim clsProducts As New ABCProducts
-
If clsProducts.IsValidPCode(Request.Params("pcode")) Then
-
txtPCode.Text = Request.Params("pcode")
-
LocateProduct()
-
End If
-
End If
-
-
End If
-
RegisterStartupScript("SetFocus", ("<script>document.getElementById('txtPCode').focus();</script>"))
-
-
End Sub
-
-
'DO NOT remove this return procedure
-
Private Sub lnkReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkReturn0.Click, lnkReturn1.Click
-
'Return to Portal
-
Response.Redirect(CType(ViewState("UrlReferrer"), String))
-
End Sub
-
-
Private Sub cmdLocate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLocate.Click
-
'A PCode has been entered and the submit button clicked
-
-
'Query the SIRBALP by PCode and load into DataSet
-
If Page.IsValid Then
-
LocateProduct()
-
End If
-
-
End Sub
-
-
Public Sub ValidatePCode(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
-
Try
-
Dim intTest As Integer = txtPCode.Text
-
Catch ex As Exception
-
e.IsValid = False
-
Exit Sub
-
End Try
-
-
'July 11, 2007
-
'Validates PCODE against AS400 to see if is valid
-
Dim sqlCmd As String = "SELECT * FROM ABCPROD.INVMSTP WHERE (PCODE = " & txtPCode.Text & ") "
-
Dim conn As New OdbcConnection(System.Configuration.ConfigurationSettings.AppSettings("AS400"))
-
Dim cmd As New OdbcCommand(sqlCmd, conn)
-
conn.Open()
-
Dim AS400reader As OdbcDataReader = cmd.ExecuteReader
-
-
AS400reader.Read()
-
-
If AS400reader.HasRows Then
-
e.IsValid = True
-
Else
-
e.IsValid = False
-
End If
-
End Sub
-
-
Private Sub LocateProduct()
-
txtPCode.Text.Trim()
-
-
Dim sqlCmd As String = "SELECT STORE_NO, PCODE, END_QTY, S#STAT " & _
-
"FROM ABCPROD.SIRBALP, ABCPROD.STRMSTP " & _
-
"WHERE ((ABCPROD.SIRBALP.STORE_NO = ABCPROD.STRMSTP.STRNO) " & _
-
"AND (S#STAT = 'A')) " & _
-
"AND (PCODE = " & txtPCode.Text & ") " & _
-
"AND (STORE_NO <> 10) " & _
-
"AND (STORE_NO <> 11) " & _
-
"AND (STORE_NO < 219) " & _
-
"AND (END_QTY > 0) " & _
-
"ORDER BY STORE_NO, PCODE, END_QTY"
-
-
Dim conn As New OdbcConnection(System.Configuration.ConfigurationSettings.AppSettings("AS400"))
-
Dim cmd As New OdbcCommand(sqlCmd, conn)
-
cmd.CommandType = CommandType.Text
-
Dim da As New OdbcDataAdapter(cmd)
-
Dim ds As New DataSet
-
da.Fill(ds)
-
-
cmd.CommandText = "SELECT PCODE, ASIZE, DESC, OHQTY " & _
-
"FROM ABCPROD.INVMSTP " & _
-
"WHERE (PCODE = " & txtPCode.Text & ") "
-
da.SelectCommand = cmd
-
da.Fill(ds, "Product")
-
-
lblPCodeValue.Text = ds.Tables("Product").Rows(0).Item("PCODE")
-
lblDescValue.Text = ds.Tables("Product").Rows(0).Item("DESC")
-
lblSizeValue.Text = ds.Tables("Product").Rows(0).Item("ASIZE")
-
lblWHQty.Text = ds.Tables("Product").Rows(0).Item("OHQTY")
-
-
lblWHHead.Visible = True
-
lblWHQty.Visible = True
-
-
' if the requestor is at a store PC, then...
-
Dim vlVisitor As New ABCNetDepartmentMenu(Request.ServerVariables("remote_addr"))
-
If vlVisitor.IsStore Then
-
Dim cmdStore As New OdbcCommand("SELECT STORE_NO, PCODE, END_QTY " & _
-
"FROM ABCPROD.SIRBALP " & _
-
"WHERE STORE_NO = " & vlVisitor.StoreNumber & _
-
" AND PCODE = " & txtPCode.Text, conn)
-
Dim daStore As New OdbcDataAdapter(cmdStore)
-
conn.Open()
-
Dim dr As OdbcDataReader = cmdStore.ExecuteReader
-
-
lblStoreQty.Text = 0
-
While dr.Read
-
lblStoreQty.Text = dr.Item("END_QTY")
-
End While
-
-
daStore.Dispose()
-
cmdStore.Dispose()
-
conn.Dispose()
-
-
lblStoreHead.Visible = True
-
lblStoreQty.Visible = True
-
End If
-
vlVisitor.Dispose()
-
-
dlProductNumbers.DataSource = ds.Tables(0)
-
dlProductNumbers.DataBind()
-
-
ds.Dispose()
-
da.Dispose()
-
cmd.Dispose()
-
conn.Dispose()
-
-
' 03/16/05 WNS Added PriceIt
-
With btnPriceIt
-
.Visible = True
-
.Attributes.Add("onclick", "NewWindow('PriceIt.aspx?pcode=" & txtPCode.Text & "','PriceLookUp',350,350,0,'center');")
-
End With
-
-
'6/29/07 Clear textbox
-
txtPCode.Text = ""
-
SetFocus(txtPCode.ClientID)
-
End Sub
-
-
'07/20/07 This procedure sets focus to specific controls.
-
Private Sub SetFocus(ByVal ClientID As String)
-
Dim Script As New System.Text.StringBuilder
-
'Dim ClientID As String = FocusControl.ClientID
-
With Script
-
.Append("<script language='javascript'>")
-
.Append("document.getElementById('")
-
.Append(ClientID)
-
.Append("').focus();")
-
.Append("</script>")
-
End With
-
RegisterStartupScript("setFocus", Script.ToString())
-
End Sub
-
End Namespace
-
Thanks
I'm tired of looking for the problem. I didn't create the code, it was the guy before me so maybe he have something that it's not allowing this to work. Here is the code if anyone can figured it out.
I remember having a similar problem to you in the past.
From what I remember, the problem was that the RegisterStartupScript method puts the JavaScript code in the <Body> portion of the Html. In order for the body to call your JavaScript function during the page's onload event, the JavaScript must exist in the <head> section of your Html.
What I to solve this solution was to put my JavaScript into an external JavaScript file hard code the import into the <head> section of my Html.
You don't need to put the JavaScript into an external file, but I'm almost certain that the JavaScript has to be defined in the <head> section in order to make the JavaScript call during your page's onload event.
eg: -
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
<HTML>
-
<HEAD>
-
<title>My Page's Title</title>
-
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
-
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
-
<meta content="VBScript" name="vs_defaultClientScript">
-
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
-
<LINK href="Styles.css" type="text/css" rel="stylesheet">
-
<script type="text/javascript">
-
onload = function()
-
{
-
document.getElementById('myTextbox').focus();
-
}
-
</script>
-
-
</HEAD>
-
Have you tried hard coding the JavaScript into the <head> section to see if this works?
-Frinny
I have tried that, don't work for me. This is how my script section on the page looks. -
<script language="javascript">
-
-
var win=null;
-
-
function NewWindow(mypage,myname,w,h,scroll,pos)
-
{
-
if(win!=null && win.open) win.close()
-
-
if(pos=="random")
-
{
-
LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
-
TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
-
}
-
-
if(pos=="center")
-
{
-
LeftPosition=(screen.width)?(screen.width-w)/2:100;
-
TopPosition=(screen.height)?(screen.height-h)/2:100;
-
}
-
else if((pos!="center" && pos!="random") || pos==null)
-
{
-
LeftPosition=0;TopPosition=20;
-
}
-
-
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
-
win=window.open(mypage,myname,settings);
-
-
if(win.focus)
-
{
-
win.focus();
-
}
-
}
-
-
function CloseNewWin()
-
{
-
if(win!=null && win.open) win.close();
-
}
-
-
onload = function()
-
{
-
document.getElementById('txtPCode').focus();
-
}
-
</script>
-
I have tried that, don't work for me. This is how my script section on the page looks.
Are you getting an JavaScript errors on the page at all?
Like an "object expected" error or the like?
As much as I hate to admit it (:-P) if you run it in firefox with that DOM parser thing on you will see a lot more hidden errors.
Are you remembering to have your body tag's onload function call out to that javascript onload thing
I'm going to ask one more small but vital question.
Are you using any use of Ajax in your html design?
Are you using the AjaxControlToolkit's UpdatePanel?
I just tried with firefox and it works, but not with Internet explorer. I didn't get any javascript error. I don't get it, whats wrong with IE (lol) then.
I'm not using AJAX in this application, this is an old application, it was develop long time before I started working here.
I just tried with firefox and it works, but not with Internet explorer. I didn't get any javascript error. I don't get it, whats wrong with IE (lol) then.
I'm not using AJAX in this application, this is an old application, it was develop long time before I started working here.
Have you checked out w3c?
Have you seen their focus() method example?
I tried their example in IE and it works fine....
Maybe you might find then answer in w3c.
Have you checked out w3c?
Have you seen their focus() method example?
I tried their example in IE and it works fine....
Maybe you might find then answer in w3c.
It doesn't seem to work with a asp button, I got this error:
Compiler Error Message: BC30390: 'ASPNET.StarterKit.Portal.ProductLookUpPage.Privat e Sub SetFocus(ClientID As String)' is not accessible in this context because it is 'Private'.
It doesn't seem to work with a asp button, I got this error:
Compiler Error Message: BC30390: 'ASPNET.StarterKit.Portal.ProductLookUpPage.Privat e Sub SetFocus(ClientID As String)' is not accessible in this context because it is 'Private'.
Could you post the html code for your aspx page?
It doesn't seem to work with a asp button, I got this error:
Compiler Error Message: BC30390: 'ASPNET.StarterKit.Portal.ProductLookUpPage.Privat e Sub SetFocus(ClientID As String)' is not accessible in this context because it is 'Private'.
'07/20/07 This procedure sets focus to specific controls.
Private Sub SetFocus(ByVal ClientID As String)
Dim Script As New System.Text.StringBuilder
'Dim ClientID As String = FocusControl.ClientID
With Script
.Append("<script language='javascript'>")
.Append("document.getElementById('")
.Append(ClientID)
.Append("').focus();")
.Append("</script>")
End With
RegisterStartupScript("setFocus", Script.ToString())
End Sub
Change the SetFocus method to be a public method instead of a private method.
Nathan
Here is the html -
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" marginwidth="0" marginheight="0">
-
<form runat="server">
-
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
-
<tr vAlign="top">
-
<td colSpan="2"><asp:placeholder id="phBanner" runat="server"></asp:placeholder></td>
-
</tr>
-
<tr>
-
<td class="contentCellTop" vAlign="top">
-
<center><br>
-
<table width="650" border="0">
-
<tr>
-
<td>
-
<TABLE id="Table1" cellSpacing="2" cellPadding="2" width="100%" border="0">
-
<TR>
-
<TD>
-
<asp:label id="lblTitle" runat="server" CssClass="Head"> Product Locate</asp:label></TD>
-
<TD>
-
<P align="right">[
-
<asp:linkbutton id="lnkReturn0" CssClass="CommandButton" Visible="True" Runat="server" EnableViewState="True"
-
Enabled="True" CausesValidation="False">return</asp:linkbutton>]</P>
-
</TD>
-
</TR>
-
</TABLE>
-
<HR noShade SIZE="1">
-
<span class="normal" id="spnContent" runat="server">
-
<P>Enter a Product Code (PCode) or look it up using the look-up function provided. Once you select a product,
-
you can find a display of stores which have the product in stock as of end
-
of business yesterday.</P>
-
<P><asp:validationsummary id="vsPCode" runat="server" CssClass="Error" Width="100%" HeaderText="The following error(s) occurred:"></asp:validationsummary></P>
-
<P align="center"><asp:textbox id="txtPCode" runat="server" Width="63px" ToolTip="Enter the PCode into this textbox."></asp:textbox><asp:requiredfieldvalidator id="rfvPCode" runat="server" CssClass="strError" ToolTip="You must enter a valid PCode to continue."
-
ControlToValidate="txtPCode" Display="Dynamic" ErrorMessage="You must enter a valid PCode to continue.">!</asp:requiredfieldvalidator><asp:regularexpressionvalidator id="revPCode" runat="server" CssClass="strError" ToolTip="The PCode can only contain 5 or 6 numbers."
-
ControlToValidate="txtPCode" Display="Dynamic" ErrorMessage="The PCode can only contain 5 or 6 numbers." ValidationExpression="\d{5,6}">!</asp:regularexpressionvalidator><asp:customvalidator id="cvPCode" runat="server" CssClass="strError" ToolTip="The Product Code entered was not found."
-
Display="Dynamic" ErrorMessage="The Product Code entered was not found." EnableClientScript="False" OnServerValidate="ValidatePCode">!</asp:customvalidator>
-
<asp:button id="cmdLocate" runat="server" CssClass="CommandButton" ToolTip="Click here to locate the product."
-
Text="Locate"></asp:button> <INPUT class="CommandButton" id="cmdLookup" onclick="this.disabled = true; NewWindow('product_lookup.aspx','ProductLookUp',550,500,0,'center');"
-
type="button" value="Look-Up PCode" name="cmdLookup"></P>
-
<P align="center">
-
<TABLE id="tblInfoContainment" cellSpacing="2" cellPadding="2" width="475" border="0">
-
<TR>
-
<TD vAlign="top">
-
<TABLE id="tblResultsLabels" cellSpacing="3" cellPadding="3" border="0">
-
<TR>
-
<TD class="strNormal" colSpan="4">Click the LOCATE button to initiate the query.</TD>
-
</TR>
-
<TR class="Normal">
-
<TD>
-
<asp:label id="lblPCodeValue" runat="server" CssClass="strNormal"></asp:label></TD>
-
<TD colSpan="2">
-
<P align="left">
-
<asp:label id="lblDescValue" runat="server" CssClass="Normal"></asp:label></P>
-
</TD>
-
<TD>
-
<asp:label id="lblSizeValue" runat="server" CssClass="Normal"></asp:label></TD>
-
</TR>
-
<TR>
-
<TD colSpan="2">
-
<asp:Label id="lblWHHead" runat="server" CssClass="strNormal" Visible="False">Warehouse O/H:</asp:Label>
-
<asp:Label id="lblWHQty" runat="server" CssClass="Normal"></asp:Label></TD>
-
<TD colSpan="2">
-
<asp:Label id="lblStoreHead" runat="server" CssClass="strNormal" Visible="False">Your Store O/H:</asp:Label>
-
<asp:Label id="lblStoreQty" runat="server" CssClass="normal" Visible="False"></asp:Label> </TD>
-
</TR>
-
</TABLE>
-
</TD>
-
<TD vAlign="bottom"><INPUT id="btnPriceIt" type="button" value="Price It!" name="btnPriceIt" runat="server"
-
class="CommandButton" tooltip="Click here to see the prices of the product in the different price zones"> </TD>
-
</TR>
-
</TABLE>
-
</P>
-
<P align="center">
-
</P>
-
<P align="center"><asp:datalist id="dlProductNumbers" runat="server" CssClass="Normal" Width="100%" RepeatColumns="5"
-
CellPadding="3" BorderColor="#DEBA84" BorderStyle="None" BackColor="#DEBA84"
-
GridLines="Both" BorderWidth="1px" CellSpacing="2">
-
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#738A9C"></SelectedItemStyle>
-
<HeaderTemplate>
-
<TABLE id="tblDataHeader" cellSpacing="0" cellPadding="3" width="100%" border="0">
-
<TR>
-
<TD align="center" class="strNormal" style="color: #ffffff;">The Product has been
-
found in the following Stores:</TD>
-
</TR>
-
</TABLE>
-
</HeaderTemplate>
-
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
-
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
-
<ItemTemplate>
-
<table id="tblDataItem" border="0" cellpadding="3" cellspacing="0" width="100%">
-
<TR>
-
<td align="left" class="strNormal"><a href='<%# "../store_info_lookup.aspx?storenumber=" & DataBinder.Eval(Container.DataItem, "STORE_NO")%>'>Store
-
<%# DataBinder.Eval(Container.DataItem, "STORE_NO")%>
-
</a>
-
<span class="Normal">(<%# DataBinder.Eval(Container.DataItem, "END_QTY")%>)</span>
-
</TR>
-
</table>
-
</ItemTemplate>
-
<HeaderStyle Font-Bold="True" ForeColor="#DEBA84" BackColor="#A55129"></HeaderStyle>
-
<AlternatingItemTemplate>
-
<table id="tblDataAltItem" border="0" cellpadding="3" cellspacing="0">
-
<TR>
-
<td align="left" class="strNormal"><a href='<%# "../store_info_lookup.aspx?storenumber=" & DataBinder.Eval(Container.DataItem, "STORE_NO")%>'>Store
-
<%# DataBinder.Eval(Container.DataItem, "STORE_NO")%>
-
</a>
-
<span class="Normal">(<%# DataBinder.Eval(Container.DataItem, "END_QTY")%>)</span>
-
</TR>
-
</table>
-
</AlternatingItemTemplate>
-
</asp:datalist></P>
-
<P align="left"><STRONG><U>Tip</U>:</STRONG> Hold down the shift key when you click on a store number to open
-
the store information in a new window.</P>
-
<P>[<asp:linkbutton id="lnkReturn1" runat="server" cssclass="CommandButton" borderstyle="none" text="Return"
-
causesvalidation="False">return</asp:linkbutton>]</span></P>
-
<P> </P>
-
</td>
-
</tr>
-
</table>
-
</center>
-
</td>
-
</tr>
-
<tr>
-
<td class="contentCellBottom"> </td>
-
</tr>
-
<tr>
-
<td class="FootBg" vAlign="middle" height="30">
-
<div align="center"><span class="SiteLink"><font color="#eeeeee">Thank you for visiting
-
ABCNet.</font></span></div>
-
</td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
'07/20/07 This procedure sets focus to specific controls.
Private Sub SetFocus(ByVal ClientID As String)
Dim Script As New System.Text.StringBuilder
'Dim ClientID As String = FocusControl.ClientID
With Script
.Append("<script language='javascript'>")
.Append("document.getElementById('")
.Append(ClientID)
.Append("').focus();")
.Append("</script>")
End With
RegisterStartupScript("setFocus", Script.ToString())
End Sub
Change the SetFocus method to be a public method instead of a private method.
Nathan
I set it to public but still gives me an error
It doesn't seem to work with a asp button, I got this error:
Compiler Error Message: BC30390: 'ASPNET.StarterKit.Portal.ProductLookUpPage.Privat e Sub SetFocus(ClientID As String)' is not accessible in this context because it is 'Private'.
You are getting this error because your button has a runat=server.
So since it is an asp button, it is trying to call the server side code called SetFocus (except this function is private and so you get an error). It is not calling the JavaScript function called SetFocus as because it is an asp button and is calling the Server Side code.
In order to call JavaScript using an asp button you'd have to do something like the following in your in your server side code:
BTN_MyButton.Attributes.Add("OnMouseUP", "SetFocus('" + TXT_myTextBox.ClientID"');")
However, the asp button will cause a PostBack event.
Since this happens your focus will be lost when the page is redisplayed in the browser.
If you were following the example from the w3c site and substituted the <input type="button"> for <asp:Button>, the example will obviously not work for these reasons.
-Frinny
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
2 posts
views
Thread by Marco Liedekerken |
last post: by
|
2 posts
views
Thread by Elliot M. Rodriguez |
last post: by
|
6 posts
views
Thread by Mike |
last post: by
|
3 posts
views
Thread by Dexter |
last post: by
|
1 post
views
Thread by psual |
last post: by
|
5 posts
views
Thread by Finn Stampe Mikkelsen |
last post: by
|
2 posts
views
Thread by Rey |
last post: by
|
reply
views
Thread by BizEd |
last post: by
|
8 posts
views
Thread by Mel |
last post: by
| | | | | | | | | | |