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

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 

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/