AAaron123
Tue Jul 29 10:55:33 CDT 2008
thanks a lot
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:uyanKTY8IHA.4608@TK2MSFTNGP06.phx.gbl...
> You have two concepts here, as I see it:
>
> Emitting blocks of JavaScript
> Adding attributes to tags
>
> Blocks of JavaScript can be created in a variety of ways. For example, you
> can do something like this:
>
> string code = "{block of code here}";
> Literal lit = new Literal(code);
> Page.Controls.Add(lit);
>
> There is probably a mistake in that code, as I am just writing on the fly,
> but it is one way to add JavaScript. The emit methods, like
> RegisterClientScriptBlock are better, as you end up placing a script block
> either a) at the top of the page or b) inline. There are two primary
> methods here (on the ClientScriptManager class):
>
> RegisterStartupScript
> RegisterClientScriptBlock
>
> But you can also avail youself of RegisterClientScriptInclude,
> RegisterClientScriptResource, etc. All fo the methods are here:
>
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager_methods.aspx
>
> That pretty covers outputting blocks, so to the attributes adding. This is
> a way of adding tags not normally exposed by the ASP.NET classes. For
> example, the code, you show sets up the following on the image:
>
> onload="resizeImg('1')"
>
> --
> 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@roadrunner.com> wrote in message
> news:ux%23temz7IHA.5596@TK2MSFTNGP02.phx.gbl...
>> 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@comcast.netNoSpamM> wrote in
>> message news:%23T70frs7IHA.2224@TK2MSFTNGP05.phx.gbl...
>>> 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@roadrunner.com> wrote in message
>>> news:ufm33wq7IHA.2348@TK2MSFTNGP06.phx.gbl...
>>>>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
>>>>
>>>>
>>>
>>
>>
>