[CLOSED] Calling UserControl Methods from parent form

  1. #1

    [CLOSED] Calling UserControl Methods from parent form

    I will try to explain this without an example (which is on a standalone network).

    I have a form that that loads two user controls. These user controls each have a number of fields on them. For testing purposes I have added a "Fillout Defaults" button on the main form that fills in all of the fields so I can routinely perform testing. When I press the button on the it calls a direct event. How can I call to the user controls to each fillout their default values.

    ...
       <ext:UserControlLoader runat="server" ID="uclGeneral Path="~/CRTS/urGeneralControl.ascx" />
       <ext:UserControlLoader runat="server" ID="uclApproval Path="~/CRTS/urApprovalControl.ascx" />
    ...
       <ext:Button runat="server" Text="Fillout Defaults" Icon="PencilAdd">
          <DirectEvents>
             <click onEvent="FilloutDefaults" />
          </DirectEvents>
       </ext:Button>
    Last edited by geoffrey.mcgill; Sep 27, 2012 at 4:05 PM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    Please look at the example.

    Example Page
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void ApplyDefaults(object sender, DirectEventArgs e)
        {
            TestUC c = (TestUC)this.UserControlLoader1.UserControls[0];
            c.ApplyDefaults();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Button runat="server" Text="Apply defautls" OnDirectClick="ApplyDefaults" />
    
        <ext:UserControlLoader ID="UserControlLoader1" runat="server" Path="TestUC.ascx" />
    </body>
    </html>
    Example User Control
    <%@ Control Language="C#" ClassName="TestUC" %>
    
    <script runat="server">
        public void ApplyDefaults()
        {
            this.Label1.Text = "Hello!";
        }
    </script>
    
    <ext:Label ID="Label1" runat="server" />
  3. #3
    Ok the example works, but I am having a tough time getting it to work with my user control definition.

    Example Page
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
       <script runat="server">
          protected void ApplyDefaults(object sender, DirectEventArgs e)
          {
             TestUC c = (TestUC)this.UserControlLoader1.UserControls[0];
             c.ApplyDefaults();
          }
       </script>
    
    <!DOCTYPE html>
    <html>
    
       <head runat="server">
          <title>Ext.NET v2 Example</title>
       </head>
    
       <body>
          <ext:ResourceManager runat="server" />
          <ext:Button runat="server" Text="Apply defautls" OnDirectClick="ApplyDefaults" />
          <ext:UserControlLoader ID="UserControlLoader1" runat="server" Path="TestUC.ascx" />
       </body>
    </html>

    Example User Control
    <%@ Control Language="C#" ClassName="TestUC" %>
       <script runat="server">
          public void ApplyDefaults()
          {
             this.Label1.Text = "Hello!";
          }
       </script>
       <ext:Label ID="Label1" runat="server" />
    My User Control CRTS/urGeneralControl.ascx
    <%@ Control Language="C#" AutoEVentWireup="true" CodeFile="urGeneralControl.ascx.cs" Inherits="CRTS_urGneralControl" %>
    
    <ext:Label ID="Label1" runat="server" />
    My User Control CRTS/urGeneralControl.ascx.cs
    public partial class CRTS_urGeneralControl : system.Web.UI.UserControl
    {
          public void ApplyDefaults()
          {
             this.Label1.Text = "Hello!";
          }
    }
    I can't figure how to call my UserControl without the definition of ClassName.
  4. #4
    I think you should use this class "CRTS_urGeneralControl".
  5. #5
    Quote Originally Posted by Daniil View Post
    I think you should use this class "CRTS_urGeneralControl".
    That makes perfect sense. Please close the thread. Hopefully I can provide harder questions in the future and not these 1st grade questions.
  6. #6
    Hope we could answer them:)

Similar Threads

  1. [CLOSED] Loading UserControl window from Parent Form throwing error
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 10, 2011, 3:43 PM
  2. [CLOSED] Calling js function from parent page
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 03, 2010, 10:50 AM
  3. [CLOSED] error when calling ajax methods or taskmanager
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 04, 2009, 7:08 AM
  4. Problem calling methods
    By Argons in forum 1.x Help
    Replies: 5
    Last Post: Aug 03, 2009, 2:04 AM
  5. Replies: 1
    Last Post: Apr 15, 2009, 3:35 PM

Posting Permissions