How to instantiate more than one copy of a Usercontrol at run time?

  1. #1

    How to instantiate more than one copy of a Usercontrol at run time?

    Is it possible from JavaScript, to instantiate multiple copies of the same UserControl at run time? For example, I have UserControl1 which displays a window. The user is allowed to click on a button multiple times to create separate instances of that same control displaying two or more of the same control in different windows. Is this possible? Any example would be appreciated.
  2. #2

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Can someone please respond to this?
  3. #3

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Can you post a .aspx code sample demonstrating what you have so far? Or, maybe you could demonstrate how you build this with just using classic <asp> control (Button, Panel, etc)?

    Geoffrey McGill
    Founder & CEO
  4. #4

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Here is some code that I have. Basically, I need to be able to display an undetermined number of distinct copies of Window1 at run time. Any help would be appreciated.

    Default.aspx:
    <%@ Page Language="VB" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <%@ Register Src="~/UserControl.ascx" TagName="UserControl" TagPrefix="uc" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
    </script>
    
    <script type="text/javascript">
        function newWindow() {
            //show new copy of Window1
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server">
        </ext:ScriptManager>
        <ext:Button ID="Button1" runat="server" Text="New Window" OnClientClick="newWindow();">
        </ext:Button>
        <ext:Window ID="Window1" runat="server" Collapsible="true" Icon="Application" Title="Title" Show&#111;nload="false" Height="400" Width="500">
            <Body>
                <uc:UserControl ID="UserControl1" runat="server" />
            </Body>
        </ext:Window>
        </form>
    </body>
    </html>

    UserControl.ascx:
    <%@ Control Language="VB" ClassName="UserControl" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
    
    </script>
    
    <script type="text/javascript">
        function saveData() {
            Ext.Msg.alert('Data Saved!', 'You entered: ' + <%= TextField1.ClientID %>.getValue());
        }
    </script>
    
    <ext:TextField ID="TextField1" runat="server">
    </ext:TextField>
    <ext:Button ID="Button1" runat="server" Text="Submit" OnClientClick="saveData();">
    </ext:Button>
  5. #5

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    I posted some code as request, but still no response. The ability to spawn separate copies of the same window and/or control is a VERY common need any most applications. For example, you can let the user enter more than one client information at the same time. So this would use the same window/control, but require two seperate instances.

    Also, in response to your comment:

    geoffrey.mcgill (5/29/2009)Can you post a .aspx code
    sample demonstrating what you have so far? Or, maybe you could
    demonstrate how you build this with just using classic <asp>
    control (Button, Panel, etc)?
    I don't currently do this in ASP, that is the point. I currently do desktop development where this is no problem at all. But this toolkit is billed as a way to create "rich" web based applications, so I would expect the same functionality to be available somehow.

    I want to keep this entirely client side, so in other words, no calls to the server to create a new control. Can someone please help me on this?
  6. #6

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Unfortunately, I don't think the scenario you describe (+code) is possible to implement using .ascx usercontrols. You'll have to hand roll the Ext.Window and form field creation code into the client, but that creates complications when trying to save the TextField values... I'm assuming you want to do more than just alert the values.

    I don't know... maybe someone else has some ideas??



    Geoffrey McGill
    Founder & CEO
  7. #7

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Hi dbassett74,

    Later today I'm going to try and come up with a sample for you.


    Geoffrey McGill
    Founder & CEO
  8. #8

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Correct. I need to get/set values.

    I started to realize that something like this is not really possible because this is not like a desktop application where you have access to the memory and therefore can instantiate things on the fly, unlike a web app that is stateless and can only utilize controls that were spit back with the page. This may be an inherent limitation of a web app, but our business requires this and I already sold management on the idea and moving full steam ahead with development (and purchasing a Professional license shortly I might add...). I don't necessarily mind hand rolling an Ext.Window and calling it from JavaScript which can instantiate a new copy, but in doing that, aren't I missing the benefits of the Coolite library such as AjaxMethods, usercontrols, etc? I guess I don't necessarily need to utilize a UserControl, but I need some way to be able to keep the code seperate for the Window if possible. I guess even a seperate JavaScript file would work, but would is till be able to call an AjaxMethod within the window??

    I would appreciate anything you can come up with. I'm sure that this is something that not only I will find valuable and would benefit from. You could even post the solution in your Examples Explorer to help other people who may have the same problem. Thanks.
  9. #9

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Just fill out your code sample with more functionality details. What should happen with the TextField values with the TextField values (other than an alert)? What functionality is included in the AjaxMethod you describe? The more details you can provide the better. I'm still a bit fuzzy on the whole scenario and I'd rather not spin my wheels trying to interpret what your requirements might be.

    Geoffrey McGill
    Founder & CEO
  10. #10

    RE: How to instantiate more than one copy of a Usercontrol at run time?

    Fair enough. I'll try and post a more detailed scenario of what I'm trying to accomplish a little bit later. Thanks.

Similar Threads

  1. Replies: 2
    Last Post: Mar 28, 2012, 1:39 PM
  2. Replies: 8
    Last Post: Feb 15, 2012, 9:04 AM
  3. Replies: 0
    Last Post: Aug 03, 2011, 10:27 PM
  4. Replies: 4
    Last Post: Apr 25, 2011, 8:35 AM
  5. Time Field Time Format Setting
    By Dinesh.T in forum 1.x Help
    Replies: 0
    Last Post: Aug 18, 2009, 3:21 AM

Posting Permissions