Best way to Register Client Script objects?

  • Thread starter Thread starter Darren Clark
  • Start date Start date
D

Darren Clark

How does everyone register and access input objects on the client side?

well... i suppose i am after some alternate ways... i use the following code to put the neccessary client javascript code so that i can then use them later...

private void RegisterClientObjects()

{

System.Text.StringBuilder sBuild = new System.Text.StringBuilder();

sBuild.Append("<script language=javascript>\n");

sBuild.Append("<!--\n");

sBuild.Append("var oSalary = document.getElementById('"+ this.Salary.ClientID.ToString() +"');\n");

sBuild.Append("var oWorkType = document.getElementById('"+ this.WorkType.ClientID.ToString() +"');\n");

sBuild.Append("//-->\n");

sBuild.Append("</script>\n");

this.Page.RegisterStartupScript("JR_LoadWorkTypeLabel",sBuild.ToString());

}
 
Hi Darren:

Instead of string builder you might consider using one large string
literal. The benefit is all the append statements do not have to
execute on each request for the page.

Maintaining javascript in a code behind file can be tedious. A few
times I have kept the script in a .js file where it can be easily
written and tested. On application startup I read the file contents
and keep the string in Cache for RegisterStartupScript.

Just a thought,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top