Usually the HTML elements have more client-side events than their server-side counterparts. For example the asp:TextBox control implements only the TextChanged server-side event while the corresponding HTML element has a few more ?? OnMouseOver, OnMouseOut, OnKeyPress, OnKeyUp, OnKeyDown, etc. If you want to ajaxify one of these client events you have to follow the instructions bellow:
Method I (add the attribute declaratively)
- Add the OnKeyUp attribute and make it call a custom function:
| ASPX |
Copy Code |
|
<asp:TextBox onkeyup="TextBoxCustomAjax('TextBox1');" ID="TextBox1" runat="server" ></asp:TextBox> |
- Implement the TextBoxCustomAjax function:
| JavaScript |
Copy Code |
|
<script type="text/javascript"> function TextBoxCustomAjax(eventArgs) { <%=RadAjaxManager1.ClientID %>.AjaxRequest(eventArgs); } </script> |
- Implement the AjaxRequest server event of the AjaxManager:
| C# |
Copy Code |
|
protected void RadAjaxManager1_AjaxRequest( object sender, Telerik.WebControls.AjaxRequestEventArgs e) { if (e.Argument == TextBox1.ClientID) { Label1.Text = TextBox1.Text; } } |
- Set from the designer that the RadAjaxManager1 will update Label1.
Method II (add the attribute from code-behind).
- Add the OnKeyUp attribute:
| C# |
Copy Code |
|
protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add( "onkeyup", RadAjaxManager1.GetAjaxRequestReference(TextBox1.ClientID)); } |
- Implement the AjaxRequest event of the RadAjaxManager:
| C# |
Copy Code |
|
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.WebControls.AjaxRequestEventArgs e) { if (e.Argument == TextBox1.ClientID) { Label1.Text = TextBox1.Text; } } |
- Set from the design-time configuration wizard that RadAjaxManager1 will update Label1.