Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Setfocus to textbox control
Message
 
À
18/08/2003 21:45:58
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
Information générale
Forum:
ASP.NET
Catégorie:
Développement mobile
Divers
Thread ID:
00821258
Message ID:
00821383
Vues:
18
>I would like a textbox to have focus at the start of the
>application.
>
>How would I code this? Im still trying to figure this one
>out.

I would probably just add the script directly to the page (as a function), then call it directly from the onload event of the Body. However, adding it the way you are should be OK (but then, I haven't added scripts that way before, so YMMV). The only change I would make in that case would be to make your code a function instead (check my typing, since I didn't type this up directly in VS.NET):
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("<script language = 'javascript'>\n");

strBuilder.Append("function SetFocus()\n");
strBuilder.Append("{\n");
strBuilder.Append("document.forms.MobileWebForm1.txtBarCodeReader.focus();\n");
strBuilder.Append("document.forms.MobileWebForm1.txtBarCodeReader.select();\n");
strBuilder.Append("}\n");

strBuilder.Append("</script>\n");

RegisterStartupScript("Focus",strBuilder.ToString());
Actually, the .select() call isn't necessary, AFAIK.

Then modify the <body tag of the HTML to call this code:
<body onload="SetFocus();">
(the body tag above would definitely be different in a real app, I just simplified it for the example - the important part is the "onload" part).
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform