This is a migrated thread and some comments may be shown as answers.

UserControl LoadTemplate() button click event not firing

11 Answers 360 Views
Window
This is a migrated thread and some comments may be shown as answers.
dstj
Top achievements
Rank 1
dstj asked on 04 Dec 2009, 10:43 PM
Hi,

I'm trying to load a UserControl in a RadWindow. It gets displayed but the button click events do not get fired.

When doing the exact same thing with a RadDock, the button click event in the UserControl gets call as expected. Here is the code used to load the UserControl (largely inspired from this thread).

Can you tell me what is wrong ? Why is the Button click event not callled with the RadWindow, but called with the RadDock ?

Thanks,

Dominic.

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!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 runat="server"
   <title></title
</head> 
<body> 
   <form id="form1" runat="server"
   <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
   <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="true" VisibleStatusbar="false" runat="server" /> 
   <telerik:RadDockLayout runat="server" ID="RadDockLayout1"
      <telerik:RadDockZone runat="server" ID="RadDockZone1" Width="300" MinHeight="200" /> 
   </telerik:RadDockLayout> 
   </form> 
</body> 
</html> 

Default.aspx.cs
      void Page_Init(object sender, EventArgs e) 
      { 
         this.EnableViewState = false
 
         RadWindow RadWindow1 = new RadWindow(); 
         RadWindow1.ID = "RadWindow1";   
         RadWindow1.VisibleOnPageLoad = true
         RadWindow1.ContentTemplate = new TestTemplate(Page); 
          
         RadWindowManager1.Windows.Add(RadWindow1); 
 
         RadDock RadDock1 = new RadDock ();   
         RadDock1.Text = RadDock1.ID = "RadDock1";   
         RadDock1.ContentTemplate = new TestTemplate(this.Page); 
  
         RadDockZone1.Controls.Add(RadDock1); 
      } 
   } 
 
   internal class TestTemplate : ITemplate 
   { 
      private Page _page; 
 
      public TestTemplate(Page page) 
      { 
         _page = page; 
      } 
 
      public void InstantiateIn(Control container) 
      { 
         System.Web.UI.UserControl userControl; 
         userControl = (System.Web.UI.UserControl)_page.LoadControl("~/TestControl.ascx"); 
         container.Controls.Add(userControl); 
      } 
   } 

TestControl.ascx
<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="TestControl.ascx.cs" Inherits="WebApplication1.TestControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
User control used as template with button events. 
<div> 
   <asp:Button ID="btn1" runat="server" Text="Button with tooltip" ToolTip="Hello World" /> 
   <asp:Button ID="btn2" runat="server" Text="Button" /> 
</div> 
<p><asp:Literal ID="ltrl" runat="server" /></p
<telerik:RadToolTipManager ID="rttm" runat="server" AutoTooltipify="true" /> 

TestControl.ascx.cs :
   public partial class TestControl : System.Web.UI.UserControl 
   { 
      override protected void OnInit(EventArgs e) 
      { 
         base.OnInit(e); 
         btn1.Click += new EventHandler(btn1_Click); 
         btn2.Click += new EventHandler(btn2_Click); 
      } 
 
      void btn1_Click(object sender, EventArgs e) 
      { 
         ltrl.Text = "Button 1 was clicked"
      } 
 
      protected void btn2_Click(object sender, EventArgs e) 
      { 
         ltrl.Text = "Button 2 was clicked"
      } 
   } 

11 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 07 Dec 2009, 11:16 AM
Hi dstj,

You can dynamically add controls to the RadWindow from code-behind by adding them to its ContentContainer as shown below:
UserListDialog.ContentContainer.Controls.Add(new LiteralControl("Dynamic Control"));


Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
dstj
Top achievements
Rank 1
answered on 07 Dec 2009, 02:25 PM
Hi, thanks for the reply, I've tried to change the code for the following, but the UserControl's button click event is still not fired.
        
RadWindow1.ContentContainer.Controls.Add(Page.LoadControl("~/TestControl.ascx")); 

So, the reported problem persists.

Dominic.
Using v2009.3.1103.35
0
dstj
Top achievements
Rank 1
answered on 09 Dec 2009, 04:15 PM
Hi again, any ideas? Can you confirm the problem?

This is quite an issue for me and I'd like to get it resolved as soon as possible. Thanks.
0
Svetlina Anati
Telerik team
answered on 10 Dec 2009, 08:43 AM
Hello dstj,

 I built up a test demo but unfortunately to no avail - the server click event was correctly fired as expected. Please, see the attached demo and let me know what should I do to reproduce the issue locally.


Greetings,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
dstj
Top achievements
Rank 1
answered on 10 Dec 2009, 02:39 PM
Hi, thanks for the reply. Your demo is somewhat incorrect though, as it does not use a RadWindowManager as I do, but a RadWindow directly in the markup. My RadWindow is created programmatically and added to the Manager.

My code:
<telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="true" VisibleStatusbar="false" runat="server" /> 

Your code:
<telerik:RadWindow ID="wnd" runat="server" VisibleOnPageLoad="true"></telerik:RadWindow> 

In your version, the events work correctly. In my version, they do not. Is my method a wrong usage? Is adding a RadWindow programmatically not supported?

Thanks,

dstj.
0
reza
Top achievements
Rank 1
answered on 10 Dec 2009, 05:47 PM
hi,
I have the same problem with the radwindow
I have a radwindowmanager in my root page and i add a radwindow dynamically to the windows collection of that.this window contains a loaded user control that i added to the ContentContainer.now when I click on buttons inside of window the pageload event fire but the postback event doesn't fire and the __EVENTTARGET is empty.
also i should tell u that I use UpdatePanel inside of my usercontrol and the buttons are inside of that(Update Panel)
Please help us.my deadline is very soon for my project.
Thanks,
Zareian Fard
0
Accepted
Svetlina Anati
Telerik team
answered on 11 Dec 2009, 11:23 AM
Hello guys,

I was able to reproduce the issue only when the radWindow is added to the RadWindowManager. The issue is already fixed as well as the problem with RadAjaxManager integration but the fix will be available in the next major release which is scheduled for the beginning of March.

For the time being what I can suggest is to use a separte RadWindow - there is no problem to have RadWindowManager declared and also additional separate RadWindows on the same page and the issue does not occur when a separate RadWindow is declared.

Let me know whether the separate RadWindow solution fixed the problem on your side.


Best wishes,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manjunath
Top achievements
Rank 1
answered on 08 May 2013, 11:51 AM
I just want to check whether this got fixed..
0
Marin Bratanov
Telerik team
answered on 10 May 2013, 10:26 AM
Hello,

A RadWindowManager tries to persist the RadWindows in its Windows collection and to recreate it from the stored state it has to first Clear() it, so dynamic controls in it will be lost, and hence postback events will not be fired for them. This concept was created first when the control had no ContentTemplate and thus did not have this behavior, and it should not be changed to preserve backwards compatibility.

When using the ContentTemplate of a RadWindow it is better to have this RadWindow standalone on the page, not as a part of a RadWindowManager. When doing so its controls will not be lost even if they are dynamic.


Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Manjunath
Top achievements
Rank 1
answered on 13 May 2013, 11:57 AM
HI Team

Thanks for reply.

Have senerio of pop up couple charts on the radwindow after clicking on the button, this is working perfectly fine. now i need make the serious of the chart to be clickable where as when user click on the particular line i need take them to the different page by doing server.transfer and pass the serious data as query string.

To achieve this have done every thing but when we click on the chart its not fire the event of chart click.

Can you please assist me on this?
0
Marin Bratanov
Telerik team
answered on 15 May 2013, 10:19 AM
Hi Manjunath,

Generally, I would advise on posting unrelated questions in separate threads to make each discussion more concise.

On the exact issue at hand - without having any concrete information on the matter I can only make several suggestions:
- if you are using RadHtmlChart - the OnClientSeriesClicked client-side event can be used and you can navigate to the desired page by using the JavaScript objects that allow you to - window.location = "desiredpage.aspx?mydata=mydata". This event also lets you obtain a lot of information about the given chart, as shown in the article I linked above.
- if you are using RadChart examine this help article on working with its server side events and this one on using JavaScript on a series click. Also, if you are using AJAX note that you cannot redirect the page on the server during a partial postback.


Greetings,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
dstj
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
dstj
Top achievements
Rank 1
Svetlina Anati
Telerik team
reza
Top achievements
Rank 1
Manjunath
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or