SolutionCottage.com
Posted  29 Oct 2008 - 04:31:47

Category: JavaScript


setting initial focus textbox asp.net

Issue:
Setting focus on a TextBox in asp.net.

Solution:

Add function:

protected void SetFocus(System.Web.UI.Page pg, Type thisType, string ControlName)
{
System.Text.StringBuilder jScript = new System.Text.StringBuilder();
jScript.Append("<script Language='JavaScript'>");
jScript.Append("document.getElementById('" + ControlName + "').focus();");
jScript.Append("</script>");
System.Web.UI.ClientScriptManager ClientScript = pg.ClientScript;
ClientScript.RegisterStartupScript(thisType, "setFocus", jScript.ToString());
}

In Page_OnLoad:

SetFocus(this.Page, this.GetType(), theControl.ClientID);








1 comment:

11/28/2016 6:17:35 AM  soaika  wrote:

I learned a lot here, many people would like me to this article. THanks


Website: http://www.abcya24.com








© SolutionCottage 2008-2011 7/26/2017 1:42:50 AM