Re: What does this ClientScriptManager code do??

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



the if is just to test if the register call has already been made. you are confusing two unrelated bits of javascript code.

the RegisterScriptBlock is used to render a javascript routine named DoClick(). the second attaches an event handler (resizeImg) to an images load event.

-- bruce (sqlwork.com)



AAaron123 wrote:
Thanks for the clear description. Now I read the Help again and see if it now makes sense. I run this in
the Page_Load event.


I've tried and it appears that you can have multiple blocks like this each with a different csname* and cstext*. Correct?



If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then

Dim cstext2 As New StringBuilder()

snip...

cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), False)

End If

MasterChurchImage.Attributes.Add("onload", "resizeImg('" + MasterChurchImage.ClientID + "')")


Also, the ...Attributes.Add is outside the If..
If that is correct it appears register should be done only once but the Add each time the page is loaded. Correct?


Thanks again


"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx> wrote in message news:%23T70frs7IHA.2224@xxxxxxxxxxxxxxxxxxxxxxx
Client script manager adds JavaScript to the page. It can be added in the header or in the body, depending on which method you use.

The last lines here are adding an attibute to the MasterChurch image, which is a way to add elements not recognized on the ASP.NET image tag which are available in HTML. In particular, this addition adds an onload event handler to the image tag. Examine the source when you run the page and you will see

<img onload="resizeImg('1')>

plus more (I purposely avoided writing the whole thing).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"AAaron123" <aaaron123@xxxxxxxxxxxxxx> wrote in message news:ufm33wq7IHA.2348@xxxxxxxxxxxxxxxxxxxxxxx
I read the help on which says:

The ClientScriptManager class is used to manage client-side scripts and add them to Web applications...


But could use a little help. Can someone tell me what the code below is used for?

If you could just put a few comments into the code that would help.

Is this code requires when ever the <script> tag is used?

The last line appears to relate to the following, but what does it do?

<asp:Image ID="MasterChurchImage" runat="server" AlternateText="Church Image" ImageUrl="~/Images/MasterChurchImage.jpg" />

THANKS for any insight



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim csname2 As String = "ButtonClickScript"

Dim cstype As Type = Me.GetType()



Dim cs As ClientScriptManager = Page.ClientScript



' Check to see if the client script is already registered.

If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then

Dim cstext2 As New StringBuilder()

cstext2.Append("<script type=text/javascript> function DoClick() {")

cstext2.Append("Form1.Message.value='Text from client script.'} </")

cstext2.Append("script>")

cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), False)

End If

MasterChurchImage.Attributes.Add("onload", "resizeImg('" + MasterChurchImage.ClientID + "')")

End Sub




.



Relevant Pages

  • Re: What does this ClientScriptManager code do??
    ... If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then ... Dim cstext2 As New StringBuilder ... event handler to the image tag. ... The ClientScriptManager class is used to manage client-side scripts and ...
    (microsoft.public.dotnet.framework.aspnet)
  • What does this ClientScriptManager code do??
    ... The ClientScriptManager class is used to manage client-side scripts and add ... Dim csname2 As String = "ButtonClickScript" ... Dim cstype As Type = Me.GetType ... If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then ...
    (microsoft.public.dotnet.framework.aspnet)
  • ASP: Get user login ID
    ... But when we register the dll on our web ... server, and call it from our ASP code, it generates an error. ... Dim lngCharsReturned As Long ...
    (microsoft.public.inetserver.iis.security)
  • RE: Problem Using VB.net Class Library DLL in VBScript
    ... In my project compile properties, I do have checked the 'Register for COM ... ' A creatable COM class must have a Public Sub New ... Dim strMyFormName As String = "Data Grid View" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: vb 6.0 naar vb.net 2005
    ... The PC has to be able to read- write data to the plc and show it in the ... starting register and such also to the module). ... starting register and such is send to the dll aswell) the dll ... Dim handle, j As Integer ...
    (microsoft.public.dotnet.languages.vb)