[CLOSED] Usercontrol, DirectMethod, Object --> Get Value

  1. #1

    [CLOSED] Usercontrol, DirectMethod, Object --> Get Value

    Hi Guys,

    Working on a large desktop project and looking for an answer. Check following files.

    I would like to get the value of Textfield tfTest (Test2.ascx) to be shown in codebehind when using a DirectMethod. But I can't. Can you explain why and what can I do to achieve my goal. I don't get an error. Just no value..

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Iwise.DefaultTest" %>
    <%@ Register Src="Test1.ascx" TagPrefix="mod" TagName="Test1" %>
    <%@ Register Src="Test2.ascx" TagPrefix="mod" TagName="Test2" %>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>I-Wise</title>
    </head>
    <body>
    <ext:ResourceManager runat="server" ID="rsmTestIwise"/>
        <ext:Desktop ID="dtIwiseTest" runat="server">
            <StartMenu Title="Keuze menu" Icon="Application" Height="500">
                <ToolConfig>
                    <ext:Toolbar runat="server" Width="110">
                        <Items>
                            <ext:Button runat="server" Text="Settings" Icon="Cog" />
                        </Items>
                    </ext:Toolbar>
                </ToolConfig>
                <MenuItems>
                    <ext:MenuItem ID="mnuTestDM" runat="server" Text="Open Test1" Icon="Car">
                         <Listeners>
                            <Click Handler="App.dtIwiseTest.getModule('modTest1').createWindow();"/>
                         </Listeners>
                    </ext:MenuItem>
                </MenuItems>
            </StartMenu>
        </ext:Desktop>
        <%--Modules from User controls--%>
        <mod:Test1 ID="ucTest1" runat="server"/>
        <mod:Test2 ID="ucTest2" runat="server"/>
    </body>
    </html>
    Default.aspx.cs
    using System;
    using System.Web.UI;
    using Ext.Net;
    
    
    namespace Iwise
    {
        public partial class DefaultTest : Page
        {
    
    
            [DirectMethod(ShowMask = true)]
            public void ShowWindow(string name)
            {
               LoadControl($"{name}.ascx");
            }
        }
    }
    Test1.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test1.ascx.cs" Inherits="iWise3.Test.Test1" %>
    <ext:DesktopModuleProxy runat="server">
        <Module ModuleID="modTest1">
            <Window>
                <ext:Window runat="server"
                    Icon="CarAdd"
                    Width="450"
                    Height="400"
                    Layout="Fit"
                    Title="Overzicht ingevoerde kilometerstanden"
                    Resizable="False"
                    Minimizable="False"
                    ID="winTest">
                    <TopBar>
                        <ext:Toolbar runat="server">
                            <Items>
                                <ext:Button runat="server" ID="btnToevoegenKmStandTest" Text="Open Test2" Icon="Add">
                                    <Listeners>
                                        <Click Handler="App.dtIwiseTest.getModule('modTest2').createWindow();" />
                                    </Listeners>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                    <Items>
                    </Items>
                </ext:Window>
            </Window>
        </Module>
    </ext:DesktopModuleProxy>
    (.cs = empty code file)

    Test2.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test2.ascx.cs" Inherits="iWise3.Test.Test2" %>
    <ext:DesktopModuleProxy runat="server">
        <Module ModuleID="modTest2">
            <Window>
                <ext:Window runat="server"
                    Icon="Table"
                    Width="400"
                    Height="260"
                    Layout="Fit"
                    Title="Invoer kilometerstand"
                    Modal="True"
                    Resizable="False"
                    Minimizable="False"
                    ID="winTest2">
                    <Items>
                        <ext:FormPanel
                            runat="server"
                            Frame="true"
                            Border="false"
                            BodyPadding="10"
                            DefaultAnchor="100%"
                            ID="frmTest1">
                            <FieldDefaults
                                LabelSeparator=" "
                                LabelAlign="Top"
                                LabelWidth="100"
                                LabelStyle="font-weight:bold;font-size:smaller;" />
                            <Defaults>
                                <ext:Parameter Name="margin" Value="0 0 10 0" Mode="Value" />
                            </Defaults>
                            <Items>
                                <ext:TextField
                                    runat="server"
                                    Flex="1"
                                    EmptyText="Add Value"
                                    HideTrigger="True"
                                    LabelAlign="Top"
                                    FieldLabel="Kilometer stand"
                                    ID="tfTest" 
                                    AllowBlank="False"
                                    />
                            </Items>
                            <DockedItems>
                                    <ext:Toolbar runat="server" Dock="Bottom">
                                        <Items>
                                            <ext:ToolbarFill runat="server"/>
                                            <ext:Button runat="server" Icon="Exclamation" text="Try to get value field in DM">
                                                <Listeners>
                                                    <Click Handler="DMKSI.ucTest2.TestObject();"/>
                                                </Listeners>
                                            </ext:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </DockedItems>
                        </ext:FormPanel>
                    </Items>
                </ext:Window>
            </Window>
        </Module>
    </ext:DesktopModuleProxy>
    Test2.ascx.cs
    [
    using System.Diagnostics;
    using Ext.Net;
    
    
    namespace iWise3.Test
    { 
        public partial class Test2 : System.Web.UI.UserControl
        {
            [DirectMethod(Namespace = "DMKSI")]
            public void TestObject()
            {
                string number = tfTest.Text;
                Debug.WriteLine($"Value: {number}");
            }
        }
    }



    Martin
    Last edited by fabricio.murta; Jul 22, 2016 at 10:08 PM.
  2. #2
    Hello Martin!

    I'm going to give it a shot before trying to run your test case, but I have reasons to believe that the test case may not be necessary for your question. Of course, if I miss the hit, we'd get to plan 2 - run the test case.

    Long story short, that's related to ASP.NET pages' life cycle. A direct method call is not a full postback call, so you don't get everything in your form POST'ed when you call a direct method. Fortunately, I must say, otherwise, calling a simple direct method to check a button validity would mean posting an entire form, possibly with a huge grid of data inside, something really cumbersome.

    Okay, the story is not so short even trying to shorten it. But here's an example that I am pretty sure that will solve your problem:
    - Direct Methods Overview - scroll down to the use case 3 in the sample and you should get what you want!

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabricio,

    Thanks for the explanation. I already expected it had something to do with the page cycle.

    I used Ext.Net 1.x to make version 1 of our app and used IFRAMES with seperate aspx pages in the desktop windows. In that scenario I could use the objects in the DirectMethods in the specifice aspx pages without a problem.

    I will have to change my code :) ..and do more on client.

    Martin
  4. #4
    Ok,

    One remark.

    Why can i do this without a problem? When trying the same in the main aspx page what I tried to achieve in a usercontrol.. it works like a charm. I can't comprehend that. But maybe I need some more study :)

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Iwise.DefaultTest" %>
    <%@ Register Src="Test1.ascx" TagPrefix="mod" TagName="Test1" %>
    <%@ Register Src="Test2.ascx" TagPrefix="mod" TagName="Test2" %>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>I-Wise</title>
    </head>
    <body>
    <ext:ResourceManager runat="server" ID="rsmTestIwise"/>
    <ext:Hidden ID="hdnTest" runat="server" Text="12345"/>
        <ext:Desktop ID="dtIwiseTest" runat="server">
            <StartMenu Title="Keuze menu" Icon="Application" Height="500">
                <ToolConfig>
                    <ext:Toolbar runat="server" Width="110">
                        <Items>
                            <ext:Button runat="server" Text="Settings" Icon="Cog" />
                        </Items>
                    </ext:Toolbar>
                </ToolConfig>
                <MenuItems>
                    <ext:MenuItem ID="mnuTestDM" runat="server" Text="Lease" Icon="Car">
                         <Listeners>
                            <Click Handler="App.dtIwiseTest.getModule('modTest1').createWindow();"/>
                         </Listeners>
                    </ext:MenuItem>
                    <ext:MenuItem ID="MenuItem2" runat="server" Text="TestDM" Icon="CarRed">
                         <Listeners>
                            <Click Handler="App.direct.TestObject();"/>
                         </Listeners>
                    </ext:MenuItem>
                </MenuItems>
            </StartMenu>
        </ext:Desktop>
        <%--Modules from User controls--%>
        <mod:Test1 ID="ucTest1" runat="server"/>
        <mod:Test2 ID="ucTest2" runat="server"/>
    </body>
    </html>
    Default.aspx.cs

    using System;
    using System.Diagnostics;
    using System.Web.UI;
    using Ext.Net;
    
    
    namespace Iwise
    {
        public partial class DefaultTest : Page
        {
    
    
            [DirectMethod(ShowMask = true)]
            public void ShowWindow(string name)
            {
               LoadControl($"{name}.ascx");
            }
    
    
            [DirectMethod]
            public void TestObject()
            {
                string number = hdnTest.Text;
                Debug.WriteLine($"Testwaarde: {number}");
            }
        }
    }
    What is the difference ?

    Martin
    Last edited by CarWise; Jul 21, 2016 at 9:12 AM.
  5. #5
    Hello CarWise!

    Did you find it amusing how code behind knew the value of the hidden field on the direct method?

    So I'll show you something even more amusing: try to get this field's value from javascript!

    I doubt you'll be able to. Why? It is not being set to the component at all during page load time. In fact, here's the code we get while loading the page for the hidden component:

    Ext.create("Ext.form.field.Hidden",{
      id: "hdnTest",
      renderTo: "App.hdnTest_Container"
    });
    Where's 12345 on the output javascript for the field? Nowhere. Why that's in code behind? Exactly because it is set in code behind, in a "static" way (on the page hardcoded aspx content). No need to be preserved in client side.

    In fact, in similar situations, you can set a textfield similar to the one in your first example, and it will always show its initial value, no matter how hard you try!..

    Not clear to you? Go ahead and change your textfield, give it an initial value, add a Text="initialVal" to the definition of your tfTest textField and give it a go!

    Open the dialog, change nothing in the textfield, click the direct event call. Voila, your sample works!.. But wait! Now change the text field, empty, anything: the direct event will be returning you the same "initialVal" over and over, because that's only what it knows about the page without having any data posted back from the client.

    I hope it helps clarify the concepts about the page life cycle. There are a number of topics on the forum already covering this subject, if you want to dive a little further in this, you may give forums search a try. A good keyword might be 'asp.net page life cycle'. Or (guessing) 'value not updated during directEvent'. Search keywords like this might give you some reasonable threads about the subject.
    Fabrício Murta
    Developer & Support Expert
  6. #6
    Thanks Fabio..

    Working with the framework for quite a while, but never used User Controls. I think that's why I'm a little stuck right now. :)
  7. #7
    Well, this current issue is actually "quite the case" even in single ASPX pages, you can reproduce this with plain single aspx file with a single text field and the directmethod handler we are talking about. Of course, and the button to call it.

    And we are never "senior enough" not to learn something new here and then, and we're here to help!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Triggering [DirectMethod] in a UserControl
    By geoffrey.mcgill in forum Examples and Extras
    Replies: 0
    Last Post: Dec 18, 2013, 4:55 AM
  2. Replies: 4
    Last Post: Dec 19, 2012, 10:58 AM
  3. Replies: 4
    Last Post: Oct 27, 2012, 11:59 AM
  4. Replies: 1
    Last Post: Sep 13, 2011, 6:19 PM
  5. Replies: 4
    Last Post: Feb 25, 2010, 10:33 AM

Posting Permissions