I am currently updating outdated "Web 1.0" code to align with modern standards.
Is there a more efficient way to create and add a client-side script without having to concatenate numerous lines into a StringBuilder and then registering it to the page using
ClientScript.RegisterStartupScript(Me.GetType(), "startUpScript", strScript)
?
Are there any alternatives (aside from consolidating everything into a global .js file) that could enhance this example? If incorporating it into the main .js file is considered the best practice, what are the reasons behind it?
Dim lsbScript As New Text.StringBuilder
lsbScript.Append(vbCrLf)
lsbScript.Append("<script language=""javascript>""" & vbCrLf)
lsbScript.Append("<!--" & vbCrLf)
...
lsbScript.Append("//-->" & vbCrLf)
lsbScript.Append("</SCRIPT>" & vbCrLf)
If Not ClientScript.IsStartupScriptRegistered("someScript") Then
ClientScript.RegisterStartupScript(Me.GetType(), "someScript", lsbScript.ToString)
End If