views:

76

answers:

1

In The Page_Load event of an ASP.NET USercontrol, I have the following Code:

    If Not Page.ClientScript.IsClientScriptIncludeRegistered("ProperCase") Then 'doesnt seem to work but no apparent harm.
        Page.ClientScript.RegisterClientScriptBlock(GetType(String), "ProperCase", GetJavaProperCase())
    End If

And here's a function that was called from above:

Private Function GetJavaProperCase() As String

    Dim Buffer As String = ""

    Buffer &= "function toProperCase(s) {" & vbCrLf
    Buffer &= "   return s.toLowerCase().replace(/^(.)|\s(.)/g," & vbCrLf
    Buffer &= "   function($1) { return $1.toUpperCase(); });" & vbCrLf
    Buffer &= "}" & vbCrLf
    Buffer &= "" & vbCrLf

    Return Buffer

End Function

When I view the emitted HTML, I see that the script is OUTSIDE of the script tags.

<script src="/BESI/WebResource.axd?d=HNVlrg1DODlFCdCw68ANPg2&amp;t=633753469952786250" type="text/javascript"></script>

function toProperCase(s) {
   return s.toLowerCase().replace(/^(.)|\s(.)/g,
   function($1) { return $1.toUpperCase(); });
}

Any idea why?

Edit:

Why is there a SRC attribute on the SCRIPT tag? That doesn't look right.

+2  A: 

Pass True to the last argument of your RegisterClientScriptBlock call:

RegisterClientScriptBlock(GetType(String), "ProperCase", GetJavaProperCase(),True)

This tells the call to add script tags for you. If you leave this off, it's false by default and you would have to add the tags to your string going out in GetJavaProperCase().

klabranche
Thank you! I loooooove this site!
Velika