public void RegisterAjaxEvent(AjaxEventType eventType, Array controlIdsToSend) { if (events == null) { events = new Hashtable(); } events[eventType] = controlIdsToSend; }
/// <summary> /// Adds an ajax event attribute to a given attribute list /// </summary> /// <param name="eventType">Type of event to add</param> /// <param name="clientId">ClientId of the widget</param> /// <param name="uniqueId">UniqueId of the widget</param> /// <param name="viewStateBuckets">Viewstate buckets to pass in the call</param> /// <param name="events">List of events</param> /// <param name="attributes">Attribute list of the widget</param> public static void AddAjaxEventAttribute(Control control, AjaxEventType eventType, string clientId, string uniqueId, string viewStateBuckets, System.Web.UI.AttributeCollection attributes) { Hashtable events = ((IAjaxHandler)control).GetRegisteredAjaxEvents(); if ((events != null && events.Contains(eventType))) { string eventName = ""; if (eventType == AjaxEventType.onAjaxClick) { eventName = "Click"; } else if (eventType == AjaxEventType.onAjaxChange) { eventName = "Change"; } string osAjaxCallScript; string osAjaxCallScriptDelayed; if (eventType == AjaxEventType.onAjaxChange) { if (control is TextBox) { // delayed on change... osAjaxCallScriptDelayed = JavaScriptManager.osAjaxCallScript(clientId, uniqueId, viewStateBuckets, eventName, true); SetJsHandlerAttribute("onoschange", osAjaxCallScriptDelayed, attributes); // on change (lost focus) sets the value immediately osAjaxCallScript = JavaScriptManager.osAjaxCallScript(clientId, uniqueId, viewStateBuckets, eventName, false); SetJsHandlerAttribute("onchange", osAjaxCallScript, attributes); } else { string jsHandlerAttributeName; if (control is CheckBox || control is RadioButton) { jsHandlerAttributeName = "onclick"; } else { jsHandlerAttributeName = "onchange"; } osAjaxCallScript = JavaScriptManager.osAjaxCallScript(clientId, uniqueId, viewStateBuckets, eventName); SetJsHandlerAttribute(jsHandlerAttributeName, osAjaxCallScript, attributes); if (control is DropDownList) { // force onchange for dropdowns after any key is pressed SetJsHandlerAttribute("onkeyup", "this.onchange();", attributes); } } } else if (eventType == AjaxEventType.onAjaxClick) { // get the code for the immediate call osAjaxCallScript = JavaScriptManager.osAjaxCallScript(clientId, uniqueId, viewStateBuckets, eventName) + " return false;"; SetJsHandlerAttribute("onclick", osAjaxCallScript, attributes); } } }