PDA

View Full Version : [CLOSED] Calling UserControl Methods from parent form



cwolcott
Sep 24, 2012, 7:41 PM
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>

Daniil
Sep 25, 2012, 7:26 AM
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" />

cwolcott
Sep 26, 2012, 5:12 PM
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.

Daniil
Sep 26, 2012, 8:59 PM
I think you should use this class "CRTS_urGeneralControl".

cwolcott
Sep 27, 2012, 3:31 PM
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.

Daniil
Sep 27, 2012, 5:06 PM
Hope we could answer them:)