Write a script to the page when writing a server control

zhaozj2021-02-12  149

When writing a server control, you often need to send a large number of client code to the page. Under normal circumstances we can use it directly

Output.write () Writes to the page, but this will bring a few questions:

1. If there is a few such server controls in the same page, is it necessary to write a few times?

2, if the page automatically runs the corresponding client script?

In fact, these issues have provided solutions in ASP.NET.

There are several ways to Page:

RegisterClientScriptblock

You can send a client code block to the page (of course, it is not just a script, or other text), this code will be written to the beginning of the Form.

IsclientScriptblockRegistered determines whether the client code sent by the RegisterClientScriptBlock based on a page level key has been sent to the client. RegisterStartupScript can send client code blocks to the page, which will be written to the end of the Form. This can be used as its name. After the page load is completed, it is written to a automatic running code ISSTARTUPScriptregister to determine whether the client code sent by the registerStartupScript is sent to several methods by the client code sent by the registerStartupScript, according to a page level key. The above two problems can be solved. Example: // Generate a client script

Private string getClientScript ()

{

Return @ "