473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegisterClientS criptBlock and "Key" Value

Hi. Two questions about "RegisterClient ScriptBlock":

1. I want to be able to insert a script block without having to worry about
whether the "key" is unique. As it turns out, if a script block with that key
has already been registered, I can't register another block with the same
key. So the problem is, if I have functions that just register script blocks,
am I going to have to dynamically generate keys for each one with some kind
of awful "counter" or something? Is there a way to leave this parameter NULL
or something and have it automatically create a new key?

2. When I provide the "Key" parameter to this function, I would have thought
that it would be somehow output as an attribute to the <script /tag that is
generated on the client. Yet the <Script /tag says nothing. So what's the
"key" for except to manage uniqueness on the server side? Maybe that *is* all
it's for.

Thanks.

Alex
Aug 4 '06 #1
2 4641
Hi,

Alex Maghen wrote:
Hi. Two questions about "RegisterClient ScriptBlock":

1. I want to be able to insert a script block without having to worry about
whether the "key" is unique. As it turns out, if a script block with that key
has already been registered, I can't register another block with the same
key. So the problem is, if I have functions that just register script blocks,
am I going to have to dynamically generate keys for each one with some kind
of awful "counter" or something? Is there a way to leave this parameter NULL
or something and have it automatically create a new key?

2. When I provide the "Key" parameter to this function, I would have thought
that it would be somehow output as an attribute to the <script /tag that is
generated on the client. Yet the <Script /tag says nothing. So what's the
"key" for except to manage uniqueness on the server side? Maybe that *is* all
it's for.

Thanks.

Alex
The key is there to avoid that a given script is rendered more than once
on the page. Let's imagine that you create a checkbox control, for
example, with special features. Let's imagine that this control uses
client-side script. Now let's imagine that you have one page with 100
such checkboxes, each one of them rendering the exact same piece of
script, and you'll get the idea.

The "key" solution is not perfect, as you found out. I am reasonably
sure that there is no way to make sure that the key is unique, but it
can be pretty much anything (in a string form), so it's rather easy to
create a unique key.

For example, you can use the full qualified type name of a control, or
maybe a GUID for an object, etc...

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 4 '06 #2
Hi Alex,

The Page class maintains a number of hashtables to track all the scripts to
be included in the response. A registered script is scoped with the type of
the page or control that uses it and is given a unique name. Attempts to
associate the same script multiple times with the same type and name are
blocked, and the script is registered and emitted only once. If you are
register the same script with a different name or in association with a
different type, the same script is emitted twice or more. If the script
contains some function definitions, as a result, a script error is raised
on the client when the script is invoked.

As a best practice, it's recommended that you check
ClientScript.Is ClientScriptBlo ckRegistered first before adding script
block. For example:

Type t = this.GetType();
string myScriptBlockKe y = "SetHomePag e";
if (!ClientScript. IsClientScriptB lockRegistered( t, myScriptBlockKe y))
{
string js = ...
ClientScript.Re gisterClientScr iptBlock(t, myScriptBlockKe y, js, true);
}

Internally, ClientScriptMan ager uses the Type+Key pair to uniquely identify
which client script block is registered or not.

As for your questions:

1. Leaving the key to null will not create a new key automatically,
actually Type+null is able to uniquely identity a script block. As far as I
know, there's no way to automatically create this key. However, it's very
easy for you to use Guid.NewGuid(). ToString() to create a unique string key.

2. The Type+key is internally used by ClientScriptMan ager to maintain the
hashtable, it's not exposed in client-side code.

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
14242
by: Nicolas Girard | last post by:
Hi, Forgive me if the answer is trivial, but could you tell me how to achieve the following: {k1:,k2:v3,...} --> ,,,...] The subtle point (at least to me) is to "flatten" values that are lists. Thanks in advance,
0
3123
by: jy2003 | last post by:
1. Does MyISAM support FOREIGN KEY constraints? When I read the online MySQL Reference Manual, it said "InnoDB also supports FOREIGN KEY constraints". Does it mean MyISAM does not support FOREIGN KEY constraints? It this is the case, what should I keep in mind when I design MyISAM tables? 2. I have seen the following CREATE statement...
5
33280
by: http://links.i6networks.com | last post by:
I want to force the users to click submit to submit the forms. How do I disable "Enter Key" which will submit the form automatically when they entered the data in text field then pressed "enter key"
5
3468
by: karteikarte | last post by:
hi, i just wondered how to retrieve the 4digit key of this script? anybody who can help? best regards Karteikarte <script type="text/javascript"> <!-- Key-code script by Bart Jellema var code=0 var mul=1
1
2157
by: Suresh | last post by:
Hi all, Here is my code, if(event.which) keycode = event.which;//For Mozilla else keycode = event.keyCode;//For IE But my problem is, the value of keycode returns 46 for pressing "DELETE" key and "." key.
2
7841
by: microsoft | last post by:
When I create a instance of web services proxy in winform, I get the exception. Stack Trace: System.ArgumentException: Item has already been added. Key in dictionary:"winbootdir" Key being added: "winbootdir" at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key,...
0
4188
by: Ralf Gedrat | last post by:
Hello! I have a Application, this throws after some time following exception: Item has already been added. Key in dictionary: "- 1" key being added: "- 1" I use Application.Run with ApplicationContext. This error message comes from deeper levels must be thrown (mscorlib.dll?!) ?.
0
2438
by: David Penne | last post by:
I have SBS 2003 and am using the built in tape backup. My question is about the registry key "Eject Tape Flag". I understand that this is an undocumented key and the only articles I can find about it on the internet reference NT 4.0. Does anyone know if this key works? I have users that would like to eject the tape after a backup and...
0
5668
by: Ismail Fatih Yıldırım | last post by:
I modified the RSACSPSample from MSDN to try out a simple commutative encryption model using RSA encryption but when i run the progrem the first encryption command works but during the second encryption command (line : encryptedData2 = RSAE...) i get a "Key not valid for use in specified state." exception error even though i provide a valid...
0
7673
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.