SlideShare a Scribd company logo
1 of 1
Download to read offline
Difference between Page.RegisterClientScriptBlock and Page.RegisterStartupScript

        S.No   Page.RegisterClientScriptBlock          Page.RegisterStartupScript

        1      RegisterClientScriptBlock places        RegisterStartupScript places the script
               the script at the top of the page       at bottom of page right before the
               right after the starting 'form' tag .   ending 'form' tag.

        2      The code cannot access any of the       The code can access any of the form's
               form's elements because, at that        elements because, at that time, the
               time, the elements have not been        elements have been instantiated.
               instantiated yet.

        3      RegisterClientScriptBlock is            RegisterStartupScript is meant for
               meant for functions that should be      commands that should execute on page
               "available" to the page. For this       load (at the client), so that page needs
               they are rendered at the start of       to be available for the script. This
               the HTML file. In this case the         script is rendered at the end of the
               page content will be blocked.           HTML file. In this case the content of
                                                       the page will be diplayed first and then
                                                       script will run.

Example for RegisterStartupScript:

if (!Page.IsStartupScriptRegistered("CH"))

  Page.RegisterStartupScript("CH", "<script>alert('Hello Friend');</script>");

Example for RegisterClientScriptBlock:

if (!Page.IsClientScriptBlockRegistered("CH"))

  Page.RegisterClientScriptBlock("CH", "<script>alert('Hello Friend');</script>");


Note:

The choice of which method to use really depends on the "order" in which we want our script to be
run by the browser when rendering the page.

Take an example of a javascript function that populates a Textbox using a javascript function when
a page is loaded. If we use the RegisterClientScriptBlock method, the javascript function will give
an error. This is because our script is placed at the top of the page when it was loaded (when the
textbox was not even created). So how can it find the textbox and populate the values. So in this
case RegisterStartupscript should be used.


And, further updates on difference between questions and answers, please visit my blog @
http://onlydifferencefaqs.blogspot.in/

More Related Content

More from Umar Ali

More from Umar Ali (20)

Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sites
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamil
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamil
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trends
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search engines
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1
 
.NET Differences List
.NET Differences List.NET Differences List
.NET Differences List
 
Difference between ajax and silverlight
Difference between ajax and silverlightDifference between ajax and silverlight
Difference between ajax and silverlight
 
Difference between is and as operators in c#
Difference between is and as operators in c#Difference between is and as operators in c#
Difference between is and as operators in c#
 
Difference between c# generics and c++ templates
Difference between c# generics and c++ templatesDifference between c# generics and c++ templates
Difference between c# generics and c++ templates
 
Var vs iEnumerable
Var vs iEnumerableVar vs iEnumerable
Var vs iEnumerable
 
Differences between get children() and getdescendants() methods
Differences between get children() and getdescendants() methodsDifferences between get children() and getdescendants() methods
Differences between get children() and getdescendants() methods
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Difference between registerclientscriptblock and registerstartupscript

  • 1. Difference between Page.RegisterClientScriptBlock and Page.RegisterStartupScript S.No Page.RegisterClientScriptBlock Page.RegisterStartupScript 1 RegisterClientScriptBlock places RegisterStartupScript places the script the script at the top of the page at bottom of page right before the right after the starting 'form' tag . ending 'form' tag. 2 The code cannot access any of the The code can access any of the form's form's elements because, at that elements because, at that time, the time, the elements have not been elements have been instantiated. instantiated yet. 3 RegisterClientScriptBlock is RegisterStartupScript is meant for meant for functions that should be commands that should execute on page "available" to the page. For this load (at the client), so that page needs they are rendered at the start of to be available for the script. This the HTML file. In this case the script is rendered at the end of the page content will be blocked. HTML file. In this case the content of the page will be diplayed first and then script will run. Example for RegisterStartupScript: if (!Page.IsStartupScriptRegistered("CH")) Page.RegisterStartupScript("CH", "<script>alert('Hello Friend');</script>"); Example for RegisterClientScriptBlock: if (!Page.IsClientScriptBlockRegistered("CH")) Page.RegisterClientScriptBlock("CH", "<script>alert('Hello Friend');</script>"); Note: The choice of which method to use really depends on the "order" in which we want our script to be run by the browser when rendering the page. Take an example of a javascript function that populates a Textbox using a javascript function when a page is loaded. If we use the RegisterClientScriptBlock method, the javascript function will give an error. This is because our script is placed at the top of the page when it was loaded (when the textbox was not even created). So how can it find the textbox and populate the values. So in this case RegisterStartupscript should be used. And, further updates on difference between questions and answers, please visit my blog @ http://onlydifferencefaqs.blogspot.in/