[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Robin Prosch via .NET 247

5/15/2005 12:23:00 PM

Hi,

I need to set focus to a textbox during page_load in a mobile web app. How can I do this? I've seen blocks of code that seem to be javascript, but mine rejects them. Here's my ASP code for the form:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Scan.aspx.vb" Inherits="PTS_Status.MobileWebForm1" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<HEAD>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="http://schemas.microsoft.com/Mobile/... name="vs_targetSchema">
</HEAD>
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm...
<mobile:form id="Form1" runat="server">
<mobile:Label id="Label1" runat="server" Font-Size="Normal" Font-Bold="False" Alignment="Center">Container ID</mobile:Label>
<mobile:TextBox id="txtContID" runat="server" Alignment="Center"></mobile:TextBox>
<mobile:Command id="cmdStart" runat="server" Alignment="Center" BreakAfter="False">Start</mobile:Command>
<mobile:Command id="cmdStop" runat="server" Alignment="Center" BreakAfter="False">Stop</mobile:Command>
<mobile:Command id="cmdComplete" runat="server" Alignment="Center">Complete</mobile:Command>
</mobile:form>
</body>

I'm trying to set focus to txtContID for scanning. I don't want the user to have to click a text box and then scan into it.

Thanks!

JP
--------------------------------
From: JP Owens

-----------------------
Posted by a user from .NET 247 (http://www.dotn...)

<Id>kkF1a40a6kuh5coDKj3u7w==</Id>
6 Answers

Luis Murguía

7/14/2005 8:57:00 PM

0

I want to do the same thing, have you solved this?, because i don´t find any
satisfactory information

I hope you can help me, i really need a solution!!!

"JP Owens via .NET 247" wrote:

> Hi,
>
> I need to set focus to a textbox during page_load in a mobile web app. How can I do this? I've seen blocks of code that seem to be javascript, but mine rejects them. Here's my ASP code for the form:
>
> <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Scan.aspx.vb" Inherits="PTS_Status.MobileWebForm1" %>
> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
> <HEAD>
> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
> <meta content="http://schemas.microsoft.com/Mobile/... name="vs_targetSchema">
> </HEAD>
> <body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm...
> <mobile:form id="Form1" runat="server">
> <mobile:Label id="Label1" runat="server" Font-Size="Normal" Font-Bold="False" Alignment="Center">Container ID</mobile:Label>
> <mobile:TextBox id="txtContID" runat="server" Alignment="Center"></mobile:TextBox>
> <mobile:Command id="cmdStart" runat="server" Alignment="Center" BreakAfter="False">Start</mobile:Command>
> <mobile:Command id="cmdStop" runat="server" Alignment="Center" BreakAfter="False">Stop</mobile:Command>
> <mobile:Command id="cmdComplete" runat="server" Alignment="Center">Complete</mobile:Command>
> </mobile:form>
> </body>
>
> I'm trying to set focus to txtContID for scanning. I don't want the user to have to click a text box and then scan into it.
>
> Thanks!
>
> JP
> --------------------------------
> From: JP Owens
>
> -----------------------
> Posted by a user from .NET 247 (http://www.dotn...)
>
> <Id>kkF1a40a6kuh5coDKj3u7w==</Id>
>

Wade

7/22/2005 10:48:00 PM

0

Same here, I used regular ASP.NET not Mobile ASP.NET, I can get the
textbox to trigger and process the data from a bar code scan once I
manually select the textbox but I can not get it to automaticly set
focus to the textbox. In normal IE on a PC I use the following code and
focus works fine.

Private Sub SetFocus(ByVal FocusControl As Control)

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

I really need to get this to work.

Any help would be useful.

Luis Murguía

7/22/2005 11:40:00 PM

0

unfortunately i didn't find any information. I think the problem is the
incapacity of the mobile project to run javascript.

If we found some alternative option it would be useful, by the way i really
need a solution of this.

That is the reason of Microsoft sucks!!!


"Wade" wrote:

> Same here, I used regular ASP.NET not Mobile ASP.NET, I can get the
> textbox to trigger and process the data from a bar code scan once I
> manually select the textbox but I can not get it to automaticly set
> focus to the textbox. In normal IE on a PC I use the following code and
> focus works fine.
>
> Private Sub SetFocus(ByVal FocusControl As Control)
>
> 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
>
> I really need to get this to work.
>
> Any help would be useful.
>
>

Wade

7/25/2005 5:20:00 PM

0

I found the following code which works for mobile.net

<mobile:Form id="Form1" runat="server">
<mobile:Panel id="Panel1" runat="server">
<mobile:DeviceSpecific id="DeviceSpecific1" Runat="server">
<Choice Filter="isHTML32">
<contenttemplate>
<Script for="window" event="onload"
language="jscript">
window.alert("HI");
window.Form1.TextBox1.focus();

</Script>
</contenttemplate>
</Choice>
</mobile:DeviceSpecific>
</mobile:Panel>
<mobile:TextBox id="TextBox1" runat="server"
text="mobile:TextBox1"></mobile:TextBox>
<mobile:TextBox id="TextBox2" runat="server"
text="mobile:TextBox2"></mobile:TextBox>
</mobile:Form>


Under normal ASP.NET the following worked

Private Sub SetFocus(ByVal FocusControl As Control)

Dim Script As New System.Text.StringBuilder
Dim ClientID As String = FocusControl.ClientID

With Script
.Append("<script for='window' event='onload'
language='javascript'>")
.Append("window.Form1.")
.Append(ClientID)
.Append(".focus();")
.Append("</script>")
End With

RegisterStartupScript("setFocus", Script.ToString())

End Sub

Then else where in your code use

SetFocus(textbox1)

Hope this helps.

Now my problem is I do not want the keyboard to come up automaticly.

wade

Luis Murguía

7/28/2005 5:21:00 PM

0

Great Wade, it work´s and was useful

Now you can play with your controls in the form, you can set the focus in
other control, so the keyboard disappear

<Script for="window" event="onload" language="jscript">

if (typeof(window.frmCliente.cmdPedidos) ==
"undefined")
window.frmCliente.txtClaveCliente.focus();
else
window.frmCliente.cmdPedidos.focus();
</Script>

"Wade" wrote:

> I found the following code which works for mobile.net
>
> <mobile:Form id="Form1" runat="server">
> <mobile:Panel id="Panel1" runat="server">
> <mobile:DeviceSpecific id="DeviceSpecific1" Runat="server">
> <Choice Filter="isHTML32">
> <contenttemplate>
> <Script for="window" event="onload"
> language="jscript">
> window.alert("HI");
> window.Form1.TextBox1.focus();
>
> </Script>
> </contenttemplate>
> </Choice>
> </mobile:DeviceSpecific>
> </mobile:Panel>
> <mobile:TextBox id="TextBox1" runat="server"
> text="mobile:TextBox1"></mobile:TextBox>
> <mobile:TextBox id="TextBox2" runat="server"
> text="mobile:TextBox2"></mobile:TextBox>
> </mobile:Form>
>
>
> Under normal ASP.NET the following worked
>
> Private Sub SetFocus(ByVal FocusControl As Control)
>
> Dim Script As New System.Text.StringBuilder
> Dim ClientID As String = FocusControl.ClientID
>
> With Script
> .Append("<script for='window' event='onload'
> language='javascript'>")
> .Append("window.Form1.")
> .Append(ClientID)
> .Append(".focus();")
> .Append("</script>")
> End With
>
> RegisterStartupScript("setFocus", Script.ToString())
>
> End Sub
>
> Then else where in your code use
>
> SetFocus(textbox1)
>
> Hope this helps.
>
> Now my problem is I do not want the keyboard to come up automaticly.
>
> wade
>
>

Luis Murguía

7/28/2005 5:38:00 PM

0

Great Wade, it works and was useful

For the problem of the keyboard you can play with your controls in the way
that you set the focus in other control, like that

<Script for="window" event="onload" language="jscript">

if (typeof(window.frmCliente.cmdPedidos) ==
"undefined")
window.frmCliente.txtClaveCliente.focus();
else
window.frmCliente.cmdPedidos.focus();
</Script>

and the keyboard disappear

I hope it works!! :-)



"Wade" wrote:

> I found the following code which works for mobile.net
>
> <mobile:Form id="Form1" runat="server">
> <mobile:Panel id="Panel1" runat="server">
> <mobile:DeviceSpecific id="DeviceSpecific1" Runat="server">
> <Choice Filter="isHTML32">
> <contenttemplate>
> <Script for="window" event="onload"
> language="jscript">
> window.alert("HI");
> window.Form1.TextBox1.focus();
>
> </Script>
> </contenttemplate>
> </Choice>
> </mobile:DeviceSpecific>
> </mobile:Panel>
> <mobile:TextBox id="TextBox1" runat="server"
> text="mobile:TextBox1"></mobile:TextBox>
> <mobile:TextBox id="TextBox2" runat="server"
> text="mobile:TextBox2"></mobile:TextBox>
> </mobile:Form>
>
>
> Under normal ASP.NET the following worked
>
> Private Sub SetFocus(ByVal FocusControl As Control)
>
> Dim Script As New System.Text.StringBuilder
> Dim ClientID As String = FocusControl.ClientID
>
> With Script
> .Append("<script for='window' event='onload'
> language='javascript'>")
> .Append("window.Form1.")
> .Append(ClientID)
> .Append(".focus();")
> .Append("</script>")
> End With
>
> RegisterStartupScript("setFocus", Script.ToString())
>
> End Sub
>
> Then else where in your code use
>
> SetFocus(textbox1)
>
> Hope this helps.
>
> Now my problem is I do not want the keyboard to come up automaticly.
>
> wade
>
>