Live Chat Icon For mobile
Live Chat Icon

How to Set Focus to Web Form Controls By Using Client-Side Script

Platform: ASP.NET| Category: Basic

<script language='javascript'>
function SetFocus()
	// W3C approved DOM code that will work in all modern browsers	
	if (document.getElementById)
     	// To support older versions of IE:
         	if (document.all)
    	return false;

<body MS_POSITIONING='GridLayout' onload='SetFocus()'>
<form id='Form1' method='post' runat='server'>
	Enter 1:
	<asp:TextBox ID='txt1' Runat='server' Width='50' />
	Enter 2:
	<asp:TextBox ID='txt2' Runat='server' Width='50' />
	<asp:Button id='Button1' runat='server' Text='Button1'></asp:Button>

Sample IE Code

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.