Several functions for registering client scripts

Source: Internet
Author: User
1 . Page. registerhiddenfield
[Overview]
This allows the Server Control to automatically register hidden fields on the form. When the htmlform Server Control is rendered, this field is sent to the page.

[Definition]
Public Virtual VoidRegisterhiddenfield (
StringHiddenfieldname,
StringHiddenfieldinitialvalue );

[Parameters]
Hiddenfieldname
The unique name of the hidden field to be rendered.
Hiddenfieldinitialvalue
Value to be outputted in a hidden form.

[Example]
registerhiddenfield ( " myhiddenfield " , " welcome to Microsoft. net! " );

2. Page. registeronsubmitstatement
 
[Overview]
Enable the page to access the client onsubmit event. The script should be a client registered elsewhereCode.
 
[Definition]
Public VoidRegisteronsubmitstatement (
StringKey,
StringScript );

[Parameters]
Key
Unique key that identifies the script block.
Script
Client script to be sent to the client.

[Example]
Registeronsubmitstatement ("Submit","Document. Write ('<H4> submit button clicked. </H4> ')");

3. Page. registerstartupscript

[Overview]
Allows the ASP. NET Server Control to issue client script blocks in the page.

[Definition]
Public Virtual VoidRegisterstartupscript (
StringKey,
StringScript );

[Parameters]
Key
Unique key that identifies the script block.
Script
The content of the script to be sent to the client.

[Remarks]
Similar to the registerclientscriptblock method<Form runat=Server>The script is issued before the end mark of the element. When a script block is issued, the object for rendering the page has been defined. Therefore,<Script>The two tags of the element.
By using the key identification script, multiple server control instances can request the script block instead of sending it to the output stream twice.
Any script block with the same key value is considered repeated.

 
[Note] Remember to add the HTML annotation mark around the script so that the script will not be rendered when the requested browser does not support the script.

[Example]
// form the script to be registered at client side.

string scriptstring = "

Scriptstring+ = "Showmessage2.innerhtml = '<H4> welcome to Microsoft. NET! </H4> '}";

Scriptstring+ = "Function page_load () {showmessage1.innerhtml =";

Scriptstring+ = "'<H4> registerstartupscript example </H4>'} <";

Scriptstring+ = "/";

Scriptstring+ = "SCRIPT>";

If(!This. Isstartupscriptregistered ("Startup"))

This. Registerstartupscript ("Startup", Scriptstring );

4. Page. registerclientscriptblock

[Overview]
Allows the ASP. NET Server Control to issue client script blocks in the page.

[Definition]
Public virtual void registerclientscriptblock (
string key,
strin G script );
[parameter]
key
identifies the unique key of the script block.
script
content of the script sent to the client.

[Remarks]
the client script is displayed in the form runat = server > the start flag of the element is issued. The script block is issued when the rendered output object is defined. Therefore, it must include script > two tags of an element.
by using the keyword to identify the script, multiple server control instances can request the script block instead of sending it to the output stream twice.
Any script block with the same key value is considered repeated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.