I am trying to add dynamic RadWindows and Buttons to an UpdatePanel (not sure how to do it with RadAjax or RadAjaxManager). When the buttons have been added I am using their ID for the OpenerID of the RadWindow.
So a simple (text visual layout of this is)
UpdatePanel
--ImageButton(s) that load(s) a RadWindow(s) when clicked
My problem is when I click the button nothing happens, I think it is an AJAX javascript issue. If I load the buttons when the page loads it works great, the problem is I need to add some dynamically and when I do this outside of the page load they do nothing.
I included sample code to show you the problem with comments.
thanks for you help!
.NET 3.5
aspx
<form id="form1" runat="server"> |
<div> |
<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true" /> |
<table class="style2"> |
<tr> |
<td> |
<asp:UpdatePanel ID="pnlSubMenu" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" > |
<Triggers> |
<asp:AsyncPostBackTrigger ControlID="btnAJAX_Search" EventName="Click" /> |
</Triggers> |
</asp:UpdatePanel> |
</td> |
<td align="right"> |
<%--Will hide this button to initiate call to pnlSubMenu later when it is working--%> |
<asp:Button ID="btnAJAX_Search" runat="server" OnClick="btnAJAX_Search_Click" Text="AJAX Add Search" /> |
</td> |
</tr> |
</table> |
<script type="text/javascript"> |
function Update_pnlSubMenu() |
{ |
__doPostBack("<%= btnAJAX_Search.ClientID %>",""); |
} |
</script> |
<table class="style1"> |
<tr> |
<td> </td> |
<td class="centerme">Center Windows Here</td> |
<td> </td> |
</tr> |
</table> |
<telerik:RadWindowManager ID="RadWindowManager1" Skin="Office2007" runat="server" |
Modal="true" Animation="Resize" VisibleStatusbar="true"> |
</telerik:RadWindowManager> |
</div> |
</form> |
C# aspx.cs
using System; |
using System.Collections; |
using System.Configuration; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.HtmlControls; |
using System.Web.UI.WebControls; |
using Telerik.Web.UI; |
namespace TestPage |
{ |
public partial class RadTest : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
//If I uncomment this out and I allow the buttons to be loaded on page load then it works |
//I want to use ajax to initiate when this, plus since this is dynamic I do not want to use visibleonload |
//BuildSubMenu(); |
} |
protected void BuildSubMenu() |
{ |
string[] urls = new string[] { "http://www.google.com", "http://www.farelogix.com", "http://www.telerik.com" }; |
pnlSubMenu.ContentTemplateContainer.Controls.Clear();//Clear them and readd for this demo purpose |
RadWindowManager1.Windows.Clear();//Clear them and readd for this demo purpose |
for (int i = 1; i < 4; i++) |
{ |
Button Btn = new Button(); |
Btn.ID = "Search" + i; |
Btn.Text = "Search " + i; |
pnlSubMenu.ContentTemplateContainer.Controls.Add(Btn); |
RadWindow radWin = new RadWindow(); |
radWin.ID = "RadWinID" + i; |
radWin.OpenerElementID = "Search" + i; |
radWin.NavigateUrl = urls[i-1]; |
RadWindowManager1.Windows.Add(radWin); |
} |
} |
protected void btnAJAX_Search_Click(object sender, EventArgs e) |
{ |
BuildSubMenu(); |
} |
} |
} |