[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

RE: TextBox.TextChanged event and key strokes

(Earl Beaman[MS])

12/23/2002 10:51:00 PM

Hi hs,

I have some information for you regarding this issue.

#1 Always test on the device and not IE. PocketPC devices only support a
subset of IE's DOM object model and events.

You can use the Text_Changed event, but only after focus changes to another
control. Thus, you will not be able to see the carriage return
/termination character from the barcode scanner in your client side code
until the user
clicks another control.

Use the following code to set focus to a control in the onload event.

<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>

Note that the textboxes are outside of the panel and the device specific.
This avoids names like "_ctl0:TextBox1". You cannot use a name like this
to set focus to a particular control.

An approach that works fairly well is to create a control that simply emits
a javascript statement to set focus to a control specified in the focus
control's properties. This control would have to be the last control on
the page to work correctly.

I also don't believe it is possible to set focus to a hidden text box. If
it could accept focus, it would have to be visible.

Earl Beaman
Microsoft Developer Support


2 Answers

hs

1/6/2003 4:12:00 PM

0

Thank you Earl (and Patrick) for your help.
Just a couple of things.

Please can you explain what you meant by the following.
I'm still new to this development environment.

>An approach that works fairly well is to create a control
that simply emits
>a javascript statement to set focus to a control
specified in the focus
>control's properties. This control would have to be the
last control on
>the page to work correctly.
>


>I also don't believe it is possible to set focus to a
hidden text box. If
>it could accept focus, it would have to be visible.
>
I'm going to check if this is the case. But I can live
with the fact if the TextBox is visible and has focus
(which you have demonstrated).
Thanks
hs

(Patrick C. Cole (MS))

1/8/2003 3:02:00 PM

0

hs,

All server controls are just classes that have common and unique methods.
They all have a common method called Render. In this method, they use a
HtmlTextWriter object to emit\output\write to the outgoing HTML stream that
is sent to the client. Exactly what is in the output varies, but it is
standard html. A render method for a textbox might look something like
this:


Public void Render(HtmlTextWriter output)
{
output.write(“<input type=text id=” + this.id + “ value=’” +
this.value + “’ >”);
}

In this method, you can write out whatever you want. You could write a
line like

output.write (“<javascript>window.form1.textbox2.focus();</javascript>”);

or more elaborate statements. And these will get rendered with your
control in the browser. This particular statement will execute when the
javascript is rendered by the browser, so it’s important to have the
control in place before the javascript executes, or the object won’t exist
yet.

So you can build a control that just writes out javascript, and has a
property that takes a string. The property is for the control id that you
want to set focus to. You could then change focus on postbacks by setting
another id in this property.

Patrick Cole
Microsoft Developer Communities

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "hs" <hs@nospam.syn>
| Sender: "hs" <hs@nospam.syn>
| References: <1ec4901c29788$b090eef0$89f82ecf@TK2MSFTNGXA01>
<9niaxDkmCHA.872@cpmsftngxa08> <lNPlC49mCHA.2668@cpmsftngxa06>
<015001c29c47$fa339210$8ef82ecf@TK2MSFTNGXA04>
<915Sb9goCHA.2504@cpmsftngxa09>
<01f901c2a29f$a837e390$8af82ecf@TK2MSFTNGXA03>
<084f01c2a6a9$84a2f0b0$d4f82ecf@TK2MSFTNGXA11>
<$HKAZs2pCHA.2652@cpmsftngxa06>
<088001c2a84b$6cc94ae0$d6f82ecf@TK2MSFTNGXA13>
<Vs3Ox1sqCHA.3108@cpmsftngxa06>
| Subject: RE: TextBox.TextChanged event and key strokes
| Date: Mon, 6 Jan 2003 07:12:36 -0800
| Lines: 25
| Message-ID: <045101c2b596$0bbd1c60$89f82ecf@TK2MSFTNGXA01>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcK1lgu9nsMUwW+VTquggiwG1kYFpA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.aspnet.mobile
| Path: cpmsftngxa06
| Xref: cpmsftngxa06 microsoft.public.dotnet.framework.aspnet.mobile:5079
| NNTP-Posting-Host: TK2MSFTNGXA01 10.40.1.47
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.mobile
|
| Thank you Earl (and Patrick) for your help.
| Just a couple of things.
|
| Please can you explain what you meant by the following.
| I'm still new to this development environment.
|
| >An approach that works fairly well is to create a control
| that simply emits
| >a javascript statement to set focus to a control
| specified in the focus
| >control's properties. This control would have to be the
| last control on
| >the page to work correctly.
| >
|
|
| >I also don't believe it is possible to set focus to a
| hidden text box. If
| >it could accept focus, it would have to be visible.
| >
| I'm going to check if this is the case. But I can live
| with the fact if the TextBox is visible and has focus
| (which you have demonstrated).
| Thanks
| hs
|