Moving the focus on a control when the page loads

Moving the focus on a control when the page loads

ASP.NET doesn’t provide a built-in method for giving a control the input focus when the page loads. In fact, you can assign the TabIndex properties to controls on a page, but you can’t use this property to set the initial focus on a control of your choice.

The following procedure provides you with the ability to do exactly this

Sub SetControlFocus(ByVal ctrl As Control)    Dim code As String = String.Format("", ctrl.ClientID)    ctrl.Page.RegisterStartupScript("SetControlFocus", code)End Sub

As you see, the procedure inserts a line of JavaScript that runs after the page has been loaded, and that gives the focus to the control you pass as an argument. Because the Page object is retrieved as a property of the control, you can store this routine in any module of your ASP.NET application. You typicall call this procedure from the Page_Load event:

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles _    MyBase.Load    SetControlFocus( TextBox2 )End Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing