This works in C# ASP.NET - not sure what you are using.
Because master page items (like buttons, etc) are prefixed with master page references, the ID "butGo" is not visible, and cannot be accessed in Javascript, even with document.getElementbyId("butGo").
To cure this, add the following to your .CS file:
public void CreateJSArrayWithClientIds(params Control[] ca)
{
if (ca.Length > 0)
{
StringBuilder arrClientIDValue = new StringBuilder();
StringBuilder arrServerIDValue = new StringBuilder();
ClientScriptManager cs = Page.ClientScript;
foreach (Control c in ca)
{
arrClientIDValue.Append("\"" +
c.ClientID + "\",");
arrServerIDValue.Append("\"" +
c.ID + "\",");
}
cs.RegisterArrayDeclaration("MyClientID",
arrClientIDValue.ToString().Remove(arrClientIDValue.ToString().Length - 1, 1));
cs.RegisterArrayDeclaration("MyServerID",
arrServerIDValue.ToString().Remove(arrServerIDValue.ToString().Length - 1, 1));
cs.RegisterStartupScript(this.Page.GetType(), "key",
"\n" +
"function GetClientId(serverId)\n" +
" {\n" +
" for(i=0; i<MyServerID.length; i++)\n" +
" {\n" +
" if ( MyServerID[i] == serverId )\n" +
" {\n" +
" return MyClientID[i];\n" +
" break;\n" +
" }\n" +
" }\n" +
" }\n", true);
}
}
Add the following to your Page_Load event:
CreateJSArrayWithClientIds(...);
where ... is the list of controls you wish to access in javascript.
e.g. CreateJSArrayWithClientIds(butGo);
Then in your javascript, use:
document.getElementById(GetClientId("id of control"));
e.g. document.getElementById(GetClientId("butGo"));