Re: What does this ClientScriptManager code do??
- From: bruce barker <nospam@xxxxxxxxxx>
- Date: Sun, 27 Jul 2008 11:25:34 -0700
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@xxxxxxxxxxxxxxxxxxxxxxxClient 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@xxxxxxxxxxxxxxxxxxxxxxxI 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
- Follow-Ups:
- Re: What does this ClientScriptManager code do??
- From: AAaron123
- Re: What does this ClientScriptManager code do??
- From: AAaron123
- Re: What does this ClientScriptManager code do??
- References:
- What does this ClientScriptManager code do??
- From: AAaron123
- Re: What does this ClientScriptManager code do??
- From: Cowboy \(Gregory A. Beamer\)
- Re: What does this ClientScriptManager code do??
- From: AAaron123
- What does this ClientScriptManager code do??
- Prev by Date: Re: Automated Security Testing
- Next by Date: Re: Online data/app repository
- Previous by thread: Re: What does this ClientScriptManager code do??
- Next by thread: Re: What does this ClientScriptManager code do??
- Index(es):
Relevant Pages
|