Best way to Register Client Script objects?

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());

}
 
S

Scott Allen

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top