A silly matter of style
A long time ago (in blog time) Fabrice pointed out this nice tip from ScottGu:
Private Sub SetFocus(ByVal controlToFocus As Control)
Dim scriptFunction As New StringBuilder
Dim scriptClientId As String
scriptClientId = controlToFocus.ClientID
scriptFunction.Append("<script language='javascript'>")
scriptFunction.Append("document.getElementById('" & scriptClientId & "').focus();")
scriptFunction.Append("</script>")
RegisterStartupScript("focus", scriptFunction.ToString())
End Sub
I think it looks nicer like this:
private void setFocus(Control controlToFocus)
{
string scriptCode = string.Format(
"<script language='javascript'>"
+ "document.getElementById('{0}').focus();"
+ "</script>",
controlToFocus.ClientID );
RegisterStartupScript("focus", scriptCode);
}
Of course, I *don't* mean the C# syntax vs. the VB.NET syntax (both languages are as powerful, which one looks better is a personal preference, please don't flame me) but to the use of String.Format() as opposed to StringBuilder. May be (just may be) StringBuilder is marginally faster, but the String.Format() code is definitively shorter and (just) probably easier to understand. Opinions?