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 <scripttag 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/javascriptfunction 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 7 2233
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" <aa*******@roadrunner.comwrote in message
news:uf**************@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 <scripttag 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/javascriptfunction 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
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)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@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" <aa*******@roadrunner.comwrote in message
news:uf**************@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 <scripttag 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/javascriptfunction 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
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)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@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" <aa*******@roadrunner.comwrote in message news:uf**************@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 <scripttag 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/javascriptfunction 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
I guess you're right I am confused.
For example, I have the following which works but I don't know why.
When I open the page the dialogbox does show.
I think I'm registering the script for PopupScript but I'd expect to have to
"call" it some place.
Registering doesn't cause it to execute does it?
Thanks for the interest
Partial Class Default_aspx
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim csname1 As String = "PopupScript"
Dim cstype As Type = Me.GetType()
Dim csm As ClientScriptManager = Page.ClientScript
If (Not csm.IsStartupScriptRegistered(cstype, csname1)) Then
Dim cstext1 As New StringBuilder()
cstext1.Append("alert('This sites...es with text.');")
csm.RegisterStartupScript(cstype, csname1, cstext1.ToString, True)
End If
End Sub
End Class
In my other reply I should have mentioned that the below helped a lot.
You're right, I was trying to tie the two together and couldn't do it.
thanks again
"bruce barker" <no****@nospam.comwrote in message
news:uZ**************@TK2MSFTNGP05.phx.gbl...
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)
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/libr...r_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" <aa*******@roadrunner.comwrote in message
news:ux****************@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)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@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" <aa*******@roadrunner.comwrote in message news:uf**************@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 <scripttag 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/javascriptfunction 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
thanks a lot
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:uy**************@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/libr...r_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" <aa*******@roadrunner.comwrote in message
news:ux****************@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)" <No************@comcast.netNoSpamMwrote in message news:%2****************@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" <aa*******@roadrunner.comwrote in message news:uf**************@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 <scripttag 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/javascriptfunction 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Chris Cioffi |
last post by:
I started writing this list because I wanted to have definite points
to base a comparison on and as the starting point of writing something
myself. After looking around, I think it would be a...
|
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: Neo The One |
last post by:
I read MSDN for VS.NET 2005 beta 1 and see that RegisterStartupScript is
declared 'obsolete'. But it does not mention what should be used instead. Can
anyone tell me what I am supposed to use in...
|
by: André |
last post by:
Hi, i'm trying to get data from a asp.net 2.0 list box. The data is filled
from javascript.
i get this error
Invalid postback or callback argument. Event validation is enabled using
<pages...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |