I have to reuse the user controls I'm creating multiple times on a single page. This user control has a listbox and a button. On clicking the button, a radwindow opens and will send some value back to the caller on close. I have to identify the appropriate user control when the pop-up closes and populate the listbox with the value returned.I'm running into two issues here. One is the question posted, how do I identify calling user control from the pop-up. Second, is something wrong on my ajaxrequest code? Even if I hardcode values, the listbox does not get populated.
Parent.aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
</telerik:RadAjaxManager>
<telerik:radwindowmanager id="RadWindowManager1" reloadonshow="true" showcontentduringload="false" runat="server" behavior="Default" initialbehavior="None" ></telerik:radwindowmanager>
<div>
<uc:Control ID="Ctrl1" runat="server"></uc:Control >
<uc:Control ID="Ctrl2" runat="server"></uc:Control >
<uc:Control ID="Ctrl3" runat="server"></uc:Control >
</div>
UserControl.ascx
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
<script type="text/javascript">
function foo() {
var oWnd = radOpen('PopUp.aspx', "Title");
oWnd.add_close(OnClientClose);
return false;
}
function OnClientClose(oWnd) {
var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
ajaxManager.ajaxRequest('Processed return value');
return false;
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="ListBox">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ListBox" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
<table>
<tr>
<td>
<asp:ListBox ID="ListBox" Width="100px" runat="server" />
</td>
<td>
<asp:Button ID="AddButton" runat="server" OnClientClick="return foo(); return false;" Text="Add" />
</td>
</tr>
</table>
UserControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
var manager = RadAjaxManager.GetCurrent(Page);
manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager1_AjaxRequest);
}
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
if (!string.IsNullOrEmpty(e.Argument))
{
ListBox.Items.Add(new RadListBoxItem(e.Argument));
//This code runs without error but does not populate the list box. I even tried to harcode the control ID against which this code should run. The code ran only for the required control but listbox was not populated.
}
}
Also, all the 3 user controls get executed on the postback. Is there a way to prevent it? It's been a while since I have dealt with user controls and telerik, so if I missed out on any crucial detail in the sample above, please let me know.I do have to use telerik but not necessarily ajaxrequest. I tried some javascript code from telerik demos to populate the listbox but that didn't work either.Any help/clues/directions appreciated
Parent.aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
</telerik:RadAjaxManager>
<telerik:radwindowmanager id="RadWindowManager1" reloadonshow="true" showcontentduringload="false" runat="server" behavior="Default" initialbehavior="None" ></telerik:radwindowmanager>
<div>
<uc:Control ID="Ctrl1" runat="server"></uc:Control >
<uc:Control ID="Ctrl2" runat="server"></uc:Control >
<uc:Control ID="Ctrl3" runat="server"></uc:Control >
</div>
UserControl.ascx
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
<script type="text/javascript">
function foo() {
var oWnd = radOpen('PopUp.aspx', "Title");
oWnd.add_close(OnClientClose);
return false;
}
function OnClientClose(oWnd) {
var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
ajaxManager.ajaxRequest('Processed return value');
return false;
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="ListBox">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ListBox" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
<table>
<tr>
<td>
<asp:ListBox ID="ListBox" Width="100px" runat="server" />
</td>
<td>
<asp:Button ID="AddButton" runat="server" OnClientClick="return foo(); return false;" Text="Add" />
</td>
</tr>
</table>
UserControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
var manager = RadAjaxManager.GetCurrent(Page);
manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager1_AjaxRequest);
}
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
if (!string.IsNullOrEmpty(e.Argument))
{
ListBox.Items.Add(new RadListBoxItem(e.Argument));
//This code runs without error but does not populate the list box. I even tried to harcode the control ID against which this code should run. The code ran only for the required control but listbox was not populated.
}
}
Also, all the 3 user controls get executed on the postback. Is there a way to prevent it? It's been a while since I have dealt with user controls and telerik, so if I missed out on any crucial detail in the sample above, please let me know.I do have to use telerik but not necessarily ajaxrequest. I tried some javascript code from telerik demos to populate the listbox but that didn't work either.Any help/clues/directions appreciated