Parameters used to add Ajax requests through the Parameter object

Source: Internet
Author: User

I have written many articles about JQueryElement. There are many Ajax calls in the JQueryElement control. To facilitate your understanding, I wrote this article to explain how the Parameter object adds parameters for Ajax.

Sample Code Download: http://zsharedcode.googlecode.com/files/JQueryElementDemo.rar

This article describes the role and usage of the Parameter object in JQueryElement:

* Preparation

* Syntax

* Parameter name

* Parameter acquisition method

* Default value

* Data type

* Custom conversion functions

* Automatically added parameters

Preparation

Before that, make sure that you know how to use some controls in JQueryElement.

Syntax

By adding Parameter, you can add parameters for Ajax calls:

The code is as follows: Copy code

<Je: Parameter
Name = "<parameter Name>" Type = "<parameter obtaining method>"
Value = "<parameter expression>" Default = "<Default Value>"
DataType = "<data type>" Provider = "<custom conversion function>"/>

<Je: Parameter Name = "name" Type = "Selector"
Value = "'# txtaname'" DataType = "String"/>

Each Parameter must be included in ParameterList, while ParameterList is the attribute of all Async objects. A Parameter named name is added in the click event.

The code is as follows: Copy code
<ClickAsync Url = "webservice. asmx" MethodName = "Save" Success ="
Function (data ){
Alert (data. d. message );
}
">
<ParameterList>
<Je: Parameter Name = "name" Type = "Selector" Value = "'# txtWName3'"/>
</ParameterList>
</ClickAsync>

 

Parameter name

If WebService is called, the parameter name and the parameter name on the server are the same, for example:

The code is as follows: Copy code

<Je: Button ID = "cmdWNet3" runat = "server">
<ClickAsync Url = "webservice. asmx" MethodName = "Save">
<ParameterList>
<Je: Parameter Name = "name" Type = "Selector" Value = "'# txtWName3'"/>
</ParameterList>
</ClickAsync>
</Je: Button>

In the code, the Parameter set for the Parameter Name attribute is named name. Therefore, the Save method requires a Parameter named name:

The code is as follows: Copy code

[WebMethod]
[ScriptMethod]
Public SortedDictionary <string, object> Save (string name)
{}

If you use ashx to receive parameters, use Request ['name.

Parameter acquisition method

There are two ways to obtain parameters. One is Selector, which indicates that the Value attribute is a Selector. The Selector selects an element on the page, usually an input element, the Value of this element is used as the parameter Value, and the other is Expression, indicating that the Value in the Value is a javascript Expression. The Value calculated by the javascript Expression will be used as the parameter Value:

The code is as follows: Copy code

<Je: Parameter Name = "name" Type = "Selector" Value = "'# txtWName3'"/>

<Je: Parameter Name = "value" Type = "Expression" Value = "123 + 321" DataType = "Number"/>
<Je: Parameter Name = "value" Type = "Expression" Value = "add (123,321)" DataType = "Number"/>

The selector # txtWName3 in the code uses single quotes, because the selector must be a string. If it is changed to Value = "myselector", the Value of the javascript variable myselector is used as the selector.

Value is used as a javascript expression in various forms. In the code, the javascript function add is also called.

Default value

The Default attribute can be used to set the Default value when the parameter value is null. It is a javascript expression.

Data type

You can use DataType to convert the parameter type. For example, if the string in the conversion text box is of the numeric type:

The code is as follows: Copy code

<Je: Parameter Name = "name" Type = "Selector" Value = "'# txtAge'" Ype = "number"/>

The DataType attribute can be set to number, boolean, string, date. In fact, the WebService on the server itself also performs some conversions. For details, refer to data types such as date conversion between Ajax and WebService.

Custom conversion functions

If DataType is set, you can set another Provider to provide a custom conversion function. The custom conversion function is called when the conversion fails. For example:

The code is as follows: Copy code

<Je: Parameter Name = "name" Type = "Selector" Value = "'# txtAge'" Ype = "number" Provider ="
Function (value ){
If (value = 'confused ')
Return 40;
Else
Return 18;
}
"/>

In the above code, if the age entered by the user is not confused, it will be converted to 40, otherwise it will be 18.

Automatically added parameters

Some parameters are automatically added to some control events. For example, pageindex and pagesize are added to FillAsync of Repeater to indicate page numbers and other information.

JQueryElement is an open-source shared code that can be downloaded on the http://code.google.com/p/zsharedcode/wiki/Download page dll or source code.

 

Welcome to panzer open source project, http://zsharedcode.googlecode.com/, which includes IEBrowser control WebBrowser to execute various js and jQuery scripts as well as recording functions and jQueryUI Asp.net controls JQueryElement

Related Article

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.