---
title: "How can you to add JavaScript to a page when performing an asynchronous postback?"  
description: "How can you to add JavaScript to a page when performing an asynchronous postback?"  
author: "Amit Singh"  
published: 2011-03-29  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/711/how-can-you-to-add-javascript-to-a-page-when-performing-an-asynchronous-postback  
category: "ajax"  
tags: ["ajax"]  
reading_time: 1 minute  

---

# How can you to add JavaScript to a page when performing an asynchronous postback?

Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(), RegisterClientScriptBlock(), RegisterClientScriptInclude(), RegisterArrayDeclaration(),RegisterClientScriptResource(), RegisterExpandoAttribute(), RegisterOnSubmitStatement() which helps to add javascript while performing an asynchronous postback.

## Answers

### Answer by Amit Singh

Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(), RegisterClientScriptBlock(), RegisterClientScriptInclude(), RegisterArrayDeclaration(),RegisterClientScriptResource(), RegisterExpandoAttribute(), RegisterOnSubmitStatement() which helps to add javascript while performing an asynchronous postback.

### Answer by Varun Agrawal

For all three, a script element is rendered after the opening form tag. Following are the differences: \
1 - RegisterClientScriptBlock - The script is specified as a string parameter. \
2 - RegisterClientScriptInclude - The script content is specified by setting the src attribute to a URL that points to a script file. \
3 - RegisterClientScriptResource - The script content is specified with a resource name in an assembly. The src attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.


---

Original Source: https://www.mindstick.com/interview/711/how-can-you-to-add-javascript-to-a-page-when-performing-an-asynchronous-postback

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
