By default the AJAX Panel ajaxifies all controls placed inside. If you want to exclude a control from ajaxifying you can use the following approach:
Attributes OnClick and __doPostBack call
- Implement the realPostBack function into your aspx/ascx file
- Add a custom OnClick attribute to the control (Button in this case).
| Example Title |
Copy Code |
|
<script type="text/javascript"> function realPostBack(eventTarget, eventArgument) { __doPostBack(eventTarget, eventArgument); } </script>
<asp:Button ID="Button1" runat="server" Text="Button" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <rad:RadAjaxPanel ID="RadAjaxPanel1" runat="server"> <asp:LinkButton ID="LinkButton1" runat="server" Text="PostBack"></asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" Text="Ajax"></asp:LinkButton> </rad:RadAjaxPanel> |
And in the code-behind (Page_Load event handler):
| C# |
Copy Code |
|
if (!Page.IsPostBack) { LinkButton1.Attributes.Add( "onclick", string.Format("realPostBack(\"{0}\", \"\"); return false;", LinkButton1.UniqueID)); } |
| VB.NET |
Copy Code |
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then LinkButton1.Attributes.Add( "onclick", String.Format("realPostBack('{0}', ''); return false;", LinkButton1.UniqueID)) End If End Sub |
If you do not have a control that registers the __doPostBack function on the page you should add the following line in the Page_Load as well:
this.Page.ClientScript.GetPostBackEventReference(this, ""); |
This will come handy when you want a single control to perform post-back for your scenario or you want to upload files from control in AJAX Panel.
Set EnableAJAX to false at OnRequestStart for the particular control/request
1. Hook OnRequestStart client event
2. Set args.EnableAJAX = false for the respective initiator
| ASPX/ASCX |
Copy Code |
|
<script type="text/javascript"> function RequestStart(sender, args) { if (args.EventTarget == "Button1") { args.EnableAjax = false; } } </script> <rad:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <rad:AjaxSetting AjaxControlID="Panel1"> <UpdatedControls> <rad:AjaxUpdatedControl ControlID="Label1" /> </UpdatedControls> </rad:AjaxSetting> </AjaxSettings> <ClientEvents OnRequestStart="RequestStart" /> </rad:RadAjaxManager> <asp:Panel ID="Panel1" runat="server"> <asp:Button ID="Button2" runat="server" Text="AJAX"/> <asp:Button ID="Button1" runat="server" Text="Postback instead of AJAX"/> </asp:Panel> |
Exclude Dynamically Loaded Controls
In case you are loading the user control dynamically, the code if (!Page.IsPostBack) in the example above in its Page_Load event handler is never executed. You can check for the attached OnClick event instead of the IsPostBack. For example:
| C# |
Copy Code |
|
protected void Page_Load(object sender, EventArgs e) { bool isOnClickAttached = false; IEnumerator keys = this.CheckBox1.Attributes.Keys.GetEnumerator(); while(keys.MoveNext()) { if(keys.Current.Equals("onClick")) { isOnClickAttached = true; break; } } if(!isOnClickAttached) this.CheckBox1.Attributes.Add( "onClick", string.Format("realPostBack(\"{0}\", \"\"); return false;", this.CheckBox1.UniqueID)); } |
| VB.NET |
Copy Code |
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim isOnClickAttached As Boolean = false Dim keys As IEnumerator = Me.CheckBox1.Attributes.Keys.GetEnumerator
While keys.MoveNext If keys.Current.Equals("onClick") Then isOnClickAttached = true End If
End While If Not isOnClickAttached Then Me.CheckBox1.Attributes.Add( "onClick", String.Format("realPostBack(\""{0}\"", \""\""); return false;", Me.CheckBox1.UniqueID)) End If End Sub |
See Also