Support for Javascript in ASP. NET

Source: Internet
Author: User

 

InASP. NETMedium,System. Web. UI. clientscriptmanagerUsed to manage scripts.ClientscriptObtain attributes. You can use this object to manage scripts on the web page.

 

Because the script may be added to the same page multiple times, or you need to check whether the script has been added to the page,ClientscriptmanagerMany methods use dictionary sets for check. When registering a script content, you need to provide a string type Resource Name, this name can be used to check whether the same script has been added to the page.

 

The usage of methods can be divided into two categories. One is used to check whether resources have been added to the page.IsregisterThe other method is used to register script Resources in the page object.Register.

 

Based on the registration content, we can also divide these methods into the following categories:

 

Array

DefinitionJavascriptArray to generateJavascriptTo the page.

InJavascriptProgram, You can define an array as follows

 

VaR arrayname = new array (){Initial Values of Arrays};

For example:

VaR myarray = new array () {"one", "two", "three "};

 

Public VoidRegisterarraydeclaration (

StringArrayname,

StringArrayvalue

)

 

Parameters:

Arrayname: Array name

Arrayvalue: The value of the array, represented by a string, is inJavascriptContent defined in curly brackets in the program

 

Script Block

 

Register the script block, which is generally usedJavascriptFunction registration to the page

 

Used to determine whether a specified script block has been registered

PublicBool isclientscriptblockregistered (

StringKey

)

 

Register the script block to the page

Public VoidRegisterclientscriptblock (

TypeType,

StringKey,

StringScript

)

 

Start script block

 

Register the startup script block, which is generally used to directly executeJavascriptThe statement is registered on the page.

 

Determine whether a specified boot script block has been registered

PublicBool isstartupscriptregistered (

StringKey

)

 

Register the startup script block

Public VoidRegisterstartupscript (

TypeType,

StringKey,

StringScript

)

 

Contains external script files

 

Determine whether a script file with the specified name has been registered

PublicBool isclientscriptincluderegistered (

StringKey

)

 

Register an external script file

Public VoidRegisterclientscriptinclude (

StringKey,

StringURL

)

 

Page element attributes

 

Define new attributes for page elements and assign values

Public VoidRegisterexpandoattribute (

StringControlid,

StringAttributename,

StringAttributevalue

)

ControlidPage ElementID

AttributenameNew attribute name

AttributevalueAttribute Value

 

Hide domain

 

Add hidden domains to the page

Public VoidRegisterhiddenfield (

StringHiddenfieldname,

StringHiddenfieldinitialvalue

)

HiddenfieldnameHide the Domain Name

HiddenfieldinitialvalueHide the value of a field

 

Register the script executed when the form is submitted.

Public VoidRegisteronsubmitstatement (

TypeType,

StringKey,

StringScript

)

 

GenerateJavascript :__ dopostback (ElementID,Parameters)Script

 

PublicString getpostbackclienthyperlink (

Control Control,

StringArgument

)

 

Compared with the previous oneJavascript:Prefix used in client Script Programming to generate a script string that sends requests back and forth to the server.

PublicString getpostbackeventreference (

Control Control,

StringArgument

)

 

Resources

 

Links generated to resources compiled into the Assembly

PublicString getwebresourceurl (

TypeType,

StringResourcename

)

Resources can be script files, image files, or any other static files. This method is often used with the followingRegisterclientscriptresourceMethod.

 

RegisterJavascriptEmbed resource files into the page

Public VoidRegisterclientscriptresource (

TypeType,

StringResourcename

)

 

Appendix

Method for adding resources to a set of programs:

1.Include files in the project

2.Select the attributes of the file and set the "generate operation" attribute to "embedded resource ".

3.Note that the default namespace is automatically added before the resource name. For example, the project's default namespace isCom. MySpace, This file isJquery. jsIf the file is added to the root directory of the project, the resource name isCom. MySpace. jquery. js. If the sub-folder is added to the project, the sub-file name is added. For example, if the Sub-folder is added to the project root directoryScriptsIn the sub-folder, the resource name is changed:Com. MySpace. scripts. jquery. js.

4.You can use either of the following methods to mark an Assembly that contains resources:

A)InAssembly. CS, Add a label

[Assembly. webresource ["Resource Name","Type"]

B)In any projectCSFile, added outside the namespace

[Assembly. webresource ["Resource Name","Type"]

 

5.UseGetwebresourceurlYou can obtainWebresource. axd.

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.