SlideShare a Scribd company logo
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

Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1
Umar Ali
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1
Umar Ali
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1
Umar Ali
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1
Umar Ali
 
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
Umar Ali
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamil
Umar Ali
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamil
Umar Ali
 
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
Umar Ali
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1
Umar Ali
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1
Umar Ali
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search engines
Umar Ali
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1
Umar Ali
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
Umar Ali
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1
Umar Ali
 
.NET Differences List
.NET Differences List.NET Differences List
.NET Differences List
Umar Ali
 
Difference between ajax and silverlight
Difference between ajax and silverlightDifference between ajax and silverlight
Difference between ajax and silverlight
Umar Ali
 
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#
Umar Ali
 
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
Umar Ali
 
Var vs iEnumerable
Var vs iEnumerableVar vs iEnumerable
Var vs iEnumerable
Umar Ali
 
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
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

Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
Sease
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 

Recently uploaded (20)

Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 

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/