At client-side you can execute your own JavaScript functions at certain stages of the AJAX request. Additionally you can use a generic JavaScript function to make explicit AJAX requests to the server from the client.
 |
You can construct the javascript function calls manually or alternatively use the server-side method GetAjaxEventReference and have Telerik RadAjax generate the necessary code for you. |
Client-side API
AjaxRequest(arguments)
The AjaxRequest(arguments) function, is used to initiate a generic AJAX request. When using this function the event target defaults to the RadAjaxPanel or RadAjaxManager instance.
|
<%=AjaxManager1.ClientID%>.AjaxRequest(arguments) |
| arguments |
The parameters, which the control had used when it raised the request |
AjaxRequest event
When it is called on the client it can be handled in the AjaxRequest event handler on the server:
| JavaScript |
Copy Code |
|
function InitiateAjaxRequest(arguments) { var ajaxManager = <%= RadAjaxManager1.ClientID %>; ajaxManager.AjaxRequest(arguments); } |
And in the code-behind:
| C# |
Copy Code |
|
private void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) { //code to handle the generic AJAX request } |
| VB.NET |
Copy Code |
|
Private Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest End Sub |
When an AJAX request is triggered using AjaxRequest function from the client, the AJAX Manager itself should be set as the AJAX initiator updating the corresponding control like this:
| ASPX |
Copy Code |
|
<rad:RadAjaxManager id="RadAjaxManager1" runat="server" OnAjaxRequest="AjaxManager_AjaxRequest"> <AjaxSettings> <rad:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <rad:AjaxUpdatedControl ControlID="TextBox1"></rad:AjaxUpdatedControl> </UpdatedControls> </rad:AjaxSetting> </AjaxSettings> </rad:RadAjaxManager> |
AjaxRequestWithTarget(eventTarget, eventArgument)
The AjaxRequestWithTarget(eventTarget, eventArgument) function can be called to simulate a postback/AJAX request send by other control (besides AjaxManager or AjaxPanel) with the specified UniqueID and specified arguments. Its execution can be handled by the correspondent event (i.e. Button_Click) on the server.
|
__doPostBack(eventTarget, eventArgument)
or
<%=AjaxPanel1.ClientID%>.AjaxRequestWithTarget(eventTarget, eventArgument) |
| eventTarget |
The control which should raise postback event. You should always use the control's UniqueID. |
| eventArgument |
This is optional argument for the event |
Note: AjaxRequestWithTarget is designed as a substitute of the standard __doPostBack function. Thus, you need to override RaisePostBackEvent
of the page in order to get its argument server-side.
Here is an example how to use AjaxRequestWithTarget:
| ASPX |
Copy Code |
|
<input type="button" onclick="AjaxRequestButton(); return false;" value="AjaxButton"> <asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button> <asp:TextBox id="TextBox1" runat="server" Text=""></asp:TextBox> <rad:RadAjaxManager id="RadAjaxManager1" runat="server"> <AjaxSettings> <rad:AjaxSetting AjaxControlID="Button1"> <UpdatedControls> <rad:AjaxUpdatedControl ControlID="TextBox1"></rad:AjaxUpdatedControl> </UpdatedControls> </rad:AjaxSetting> </AjaxSettings> </rad:RadAjaxManager> |
| JavaScript |
Copy Code |
|
function AjaxRequestButton(arguments) { var ajaxManager = <%= RadAjaxManager1.ClientID %>; ajaxManager.AjaxRequestWithTarget( } |
And in the code-behind:
| C# |
Copy Code |
|
protected void Button1_Click(object sender, System.EventArgs e) { TextBox1.Text = DateTime.Now.ToLongTimeString(); } |
| Example Title |
Copy Code |
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = DateTime.Now End Sub |
You can see the working example by following this link:
http://www.telerik.com/demos/aspnet/Ajax/Examples/Manager/ClientSideAPI/DefaultCS.aspx
See Also