Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Setting focus to a control, browser independence?
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00849502
Message ID:
00855093
Vues:
22
Thank you,
Sounds like a plan.

Regards,
Neil

>Neil,
>
>While I'm not positive of the impact of this in other browsers, and even each browser could be a bit different, I would reccomend wrapping this in a javascript try catch block in case it would actually throw an error to the client if it doesn't work as expected.
>
>Additionally, I've sometimes put a javascript function in that I only call when I have a development flag set in my web.config that displays javascript exception information in an alert box when I have it set for those instances where I wrap code I'm concerned about in non-IE browsers into a try catch.
>
>As always, it's better yet to have those browsers to test in. I tend to test in mozilla firebird on windows, and in many cases, also test in mozilla and mozilla firebird on linux as well not just for scripting logic, but look and feel as well.
>
>regards,
>
>Jim Erwin
>
>>Hi mm.netters,
>>
>>In an attempt to make my web forms more user friendly, I added the following method to my base form so that I can set focus to any control:
>>
>>
>>private void SetFocus(Control FocusControl)
>>{
>>	System.Text.StringBuilder Script = new System.Text.StringBuilder();
>>	string ClientID = FocusControl.ClientID;
>>	Script.Append("<script language='javascript'>");
>>	Script.Append("document.getElementById('");
>>	Script.Append(ClientID);
>>	Script.Append("').focus();");
>>	Script.Append("</script>");
>>	this.RegisterStartupScript("SetFocus", Script.ToString());
>>}
>>
>>
>> Now I can set focus to any control on my web form by placing the following code in any event.
>>
>>
>>  this.SetFocus(myControl)
>>
>>
>>I would appreciate those of you who have experience with browsers other that IE to comment on the impact this code will have if included in my base form. I also would like to know if anyone knows how to position the cursor of a textbox control at a specific spot in the text string after the textbox receives focus.
>>
>>Regards to all,
>>Neil
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform