Fail to set the cursor to the textbox of my choice

K

Knut-Olav Traa

Comfort said:
How can I set the cursor into the textbox of my choice using VB.NET on a
webform?

You have to use javascript to set focus to the textbox.

Add these attributes to the body tag of your form:

<body id="bodyElement" runat="server">

Add this line to the code behind in the webform class:
Protected bodyElement As System.Web.UI.HtmlControls.HtmlGenericControl

Add this line to the Page_Load method:
bodyElement.Attributes.Add("onload", "Form1.TextBox1.focus()")

where "Form1" is the id of your form, and "TextBox1" is the id of the textbox.

Regards,
Knut-Olav Traa
Bekk Consulting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top