Client callback checks whether the user name is registered

Source: Internet
Author: User
The following is an introduction to the clientscriptmanager class in msdn logging.

ClientscriptmanagerClass is used to manage client scripts and add them to Web ApplicationsProgram. You can obtainClientscriptmanagerClass reference.

By adding scripts to the HTML Tag of a webpage, you can add client scripts to the webpage in declarative mode. However, in some cases, you need to dynamically add client scripts. To dynamically Add a script, use the registerclientscriptblock method, registerclientscriptinclude method, registerstartupscript method, or registeronsubmitstatement method based on the time and method you want to add the script. For more information, see .

ClientscriptmanagerClass pass key And Uniquely identifies a script. Scripts with the same key and type are considered as repeated scripts. Using script types helps avoid obfuscation of similar scripts that may be used in pages from different user controls.

The server is running from the client without sending backCodeYou can useClientscriptmanagerClass to call the client callback. This is called an out-of-band callback to the server. In the client callback, the client script function sends an asynchronous request to the ASP. NET webpage. Modify the normal lifecycle of a webpage to process callback. Use the getcallbackeventreference method to obtain a reference to the client function. When this function is called, it starts a client callback for server-side events. For more information, see .

Note:

Script callback cannot be used in earlier browsers that do not support the Document Object Model (DOM) and requires the client to enable ecmascript. To check whether the client browser supports callback, use Attribute, which can be accessed through ASP. NET Internal object Attribute access.

Use the getpostbackeventreference method and the getpostbackclienthyperlink method to define the client sending back event. These methods enable client-side scripting functions. When these functions are called, they will prompt the server to send back to this page. The difference between client-side sending and client-side callback is that a normal life cycle is required for processing client sending events on the webpage.

Note:

If you are using And Set propertyFalse, You can useGetpostbackeventreferenceMethod returnButtonControl.

AvailableButtonControls, Controls and Control Properties to run the client script.

Assume that the textbox txtusername on the page is the user name to be registered, and <span id = "Results"> </span> dynamically displays whether to register
The following describes how to register JavaScript on the page, including GetUserName, receiveserverdata, and calltheserveer.

String Clientscript;
Clientscript =   " Function GetUserName () {var username = Document. getelementbyid (' "   + Txtusername. clientid +   " '). Value; calltheserver (username ,'');} " ;
Clientscript + =   " Function exploreserverdata (Rvalue) {results. innerhtml = rvalue ;} " ;
Clientscript + =   " Function calltheserver (ARG, context) "   +   " { "   + Cbreference +   " }; " ;
String cbreference = Page. clientscript. getcallbackeventreference ( This , " ARG " , " Receiveserverdata " , " Context " );
Page. clientscript. registerstartupscript ( This . GetType (), " Abcdefg " , Clientscript, True );

The system. Web. UI. icallbackeventhandler interface member is also implemented. Icallbackeventhandler Member # Region Icallbackeventhandler Member

Protected   String Result;
Public   String Getcallbackresult ()
{
ReturnResult;
}

Public   Void Raisecallbackevent ( String Eventargument)
{
Membersbll MB =   New Membersbll ();
If (Mb. getuser (eventargument) =   Null )
Result =   " User Name " + Eventargument +   " Not registered yet " ;
Else
Result =   " User Name "   + Eventargument +   " Already registered " ;
}

# Endregion

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.