RadControls for ASP.NET AJAX 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:
CopyASPX
<asp:TextBox onkeyup="TextBoxCustomAjax('TextBox1');" ID="TextBox1" runat="server">
</asp:TextBox> 2. Implement the TextBoxCustomAjax function:
CopyJavaScript
function TextBoxCustomAjax(eventArgs) {
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(eventArgs);
}
Implement the AjaxRequest server event of the AjaxManager:
CopyC#
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
if (e.Argument == TextBox1.ClientID)
{
Label1.Text = TextBox1.Text;
}
}
CopyVB
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs)
If e.Argument = TextBox1.ClientID Then
Label1.Text = TextBox1.Text
End If
End SubSet from the designer that the RadAjaxManager1 will update Label1.
Method II (add the attribute from code-behind).
Add the OnKeyUp attribute:
CopyC#
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onkeyup", RadAjaxManager1.GetAjaxRequestReference(TextBox1.ClientID));
}
CopyVB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Attributes.Add("onkeyup", RadAjaxManager1.GetAjaxRequestReference(TextBox1.ClientID))
End Sub 2. Implement the AjaxRequest event of the RadAjaxManager:
CopyC#
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
if (e.Argument == TextBox1.ClientID)
{
Label1.Text = TextBox1.Text;
}
}
CopyVB
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs)
If e.Argument = TextBox1.ClientID Then
Label1.Text = TextBox1.Text
End If
End Sub 3. Set from the design-time configuration wizard that RadAjaxManager1 will update Label1.