Click here to Skip to main content
11,577,258 members (59,872 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I'm searching for an ans for the below quest,
You are implementing custom ASP.NET server controls.
Each control requires its own Client JavaScript code inorder to function properly.
The JavaScript uses functions that includes proper HTML elements for the control.
You need to ensure that the JavaScript for each of these controls that is used in ASP.NET is included in the generated HTML page only once,even if the ASP.NET page uses multiple instances of the given control,
Add the foll. Code line to the Page_Load method of each control, where classname is the name of the control class and strJavaScript contains the JavaScript Code for the control
Options:

a. Page.ClientScript.RegisterStartUpScript(typeof(ClassName),"script",strJavaScript)
b. Page.ClientScript.RegisterClientScriptBlock(typeof(ClassName),"script",strJavaScript)
Posted 3-Jan-13 1:38am
Tejal S1.9K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

a. When you use RegisterStartupScript, it will render your script after all the elements in the page (right before the form's end tag). This enables the script to call or reference page elements without the possibility of it not finding them in the Page's DOM.

b. When you use RegisterClientScriptBlock, the script is rendered right after the Viewstate tag, but before any of the page elements. Since this is a direct script (not a function that can be called, it will immediately be executed by the browser. But the browser does not find the label in the Page's DOM at this stage and hence you should receive an "Object not found" error.

For more information check this link
http://stackoverflow.com/questions/666519/difference-between-registerstartupscript-and-registerclientscriptblock[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 155
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 676
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100