Hi..
If you are inheriting the page from a master page then in the page load of the Content page find the body control of the master page and attach the onload function to it ..
Here is the sample just try with this…
Master Page Body Tag
<body id="MainBody" runat="server">
In the Content page where you want to make the textbox focus
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl body = this.Master.FindControl("MainBody") as HtmlGenericControl;
body.Attributes.Add("onLoad", " document.getElementById('txtUserName').focus();");
}
This should get you out of the problem.