How can Get focus on textbox when page load in asp.net

Hello friends today you will learn how to use javascript function and call him on body load in asp.net

Step 1: You make a new web site as You know and then Select Your Default.aspx page and Go into source of your page

And Write down code as given below

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<head runat=”server”>
<script type=”text/javascript” language=”javascript” >
function getfocus() {
document.getElementById(“Text1“).focus();
}
</script>
<title></title>
</head>
<body onload=”Javascript:getfocus()”>
<form id=”form1″ runat=”server”>
<div>
<input id=”Text1″ type=”text” runat=”server”  /></div>
</form>
</body>
</html>
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s