web analytics
How to Add Client Script Dynamically to ASP.NET Web Pages Options
codeling
Posted: Friday, February 17, 2017 10:03:22 AM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 915
Points: 3843

Using server code, you can add client script to a page. Creating client script in server code is useful when the contents of the client script depend on information that is not available until run time. Adding client script to the page dynamically is also useful when you want the client script to execute in the following situations:

  • When the page has finished loading
  • When users submit the page

To add client script to an ASP.NET Web page dynamically in the server code, call one of the methods listed in the following table.

Method

Description

RegisterClientScriptBlock

Adds a script block to the top of the page. You create the script as a string, and then pass it to the method, which adds it to the page. You can use this method to insert any script into the page. Note that the script might be rendered into the page before all the elements are finished; therefore, you might not be able to reference all the elements on the page from the script.

RegisterClientScriptInclude

Similar to the RegisterClientScriptBlock method, but adds a script block that references an external .js file. The include file is added before any other dynamically added script; therefore, you might not be able to reference some elements on the page.

RegisterStartupScript

Adds a script block into the page that executes when the page finishes loading but before the page's onload event is raised. The script is typically not created as an event handler or function; it generally includes only the statements you want to execute once.

RegisterOnSubmitStatement

Adds script that executes in response to the page's onsubmit event. The script is executed before the page is submitted, and gives you an opportunity to cancel the submission.

 

Sponsor
Posted: Friday, February 17, 2017 10:03:22 AM
 
Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.