I am trying to develop a framework that is extensible through user controls. In order to do this, I need to be able to use a UserControl as the target of an ajax request and I need to be able to pass an argument with it. I have done this through the implementation of IPostBackEventHandler. However when it posts back, depending on the browser, it doesn't refresh the UI(IE) or it never shows the loading panel. the "btnUpdateLabel", button always works and is there as a check. the "btnClientScript" uses JS to do the ajaxrequestwithtarget which does not show the loading panel.
below are the contents of 4 files to replicate this.
aspx
aspx.cs
ascx
ascx.cs
below are the contents of 4 files to replicate this.
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserControlPage.aspx.cs" Inherits="UserControlPage" %><%@ Register src="UserControls/PostBackeEventHandlerTest.ascx" tagname="PostBackeEventHandlerTest" tagprefix="uc2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="mgrScript" runat="server"> </telerik:RadScriptManager> <telerik:RadAjaxManager ID="mgrAjax" runat="server"> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="pnlLoading" runat="server" Skin="Default"> </telerik:RadAjaxLoadingPanel> <uc2:PostBackeEventHandlerTest ID="PostBackeEventHandlerTest1" runat="server" /> </form></body></html>aspx.cs
using System;using System.Web.UI;using Telerik.Web.UI;using System.Collections.Generic;using System.Web.UI.WebControls;using System.Collections;public partial class UserControlPage : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { //increase the request queue so we can have multiple requests loading. RadAjaxManager.GetCurrent(this.Page).RequestQueueSize = 50; } }ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PostBackeEventHandlerTest.ascx.cs" Inherits="UserControls_PostBackeEventHandlerTest" %><telerik:RadAjaxLoadingPanel ID="pnlLoading" Runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel><asp:Label ID="lblButtonTarget" runat="server" Text="Updated From Button"></asp:Label><br /><asp:Button ID="btnUpdateLabel" runat="server" Text="Update Time Regular" /><br /><br /><asp:Button ID="btnClientScript" runat="server" Text="Update Time ClientScript" /><br /><br /><asp:Label ID="lblPostbackevent" runat="server" Text="Updated From PostBack"></asp:Label>ascx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class UserControls_PostBackeEventHandlerTest : System.Web.UI.UserControl,IPostBackEventHandler{ protected void Page_Load(object sender, EventArgs e) { var mgr = Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page); mgr.AjaxSettings.AddAjaxSetting(this.btnUpdateLabel, this.lblButtonTarget, this.pnlLoading); mgr.AjaxSettings.AddAjaxSetting(mgr, this.lblPostbackevent, this.pnlLoading); this.btnUpdateLabel.Click += new EventHandler(btnUpdateLabel_Click); this.btnClientScript.OnClientClick = "var mgr = $find('" + mgr.ClientID + "');mgr.ajaxRequestWithTarget('" + this.UniqueID + "', 'I need to pass a param');"; } void btnUpdateLabel_Click(object sender, EventArgs e) { this.lblButtonTarget.Text = DateTime.Now.ToString(); } public void RaisePostBackEvent(string eventArgument) { this.lblPostbackevent.Text = DateTime.Now.ToString(); }}