Clientside Control Changes Not visible in C#

  1. #1

    Clientside Control Changes Not visible in C#

    <script type="text/javascript">
    
    function Work(id)
    {
      Ext.getCmp('TestId').Text = id;
    }
    
    </script>
    <ext:Hidden runat="server" ID="TestId" />
    
    <ext:Button runat="server" Text=" Test ">
        <DirectEvents>
            <Click OnEvent="Click">
                <EventMask ShowMask="true" Msg="Working..." />
            </Click>
        </DirectEvents>
    </ext:Button>
    [Ext.Net.DirectMethod]
    public void Click(object sender, Ext.Net.DirectEventArgs e)
    {
        string id = TestId.Text;
    }
    • Outside application calls Work method with '12345'
    • Work method changes EXT control's text value to 12345
    • User then clicks on the button to call the direct method.
    • Expected: TestId's text value should be '12345'.
    • Actual: The value is ""

    WHY?
    Last edited by geoffrey.mcgill; Mar 26, 2012 at 3:22 PM.
  2. #2
    Dear Sir, you are calling a Direct Event, then why there is a [DirectMethod] attribute flagged before your Click handler!?! And I can't see any call to your 'Work' function.
    Last edited by geoffrey.mcgill; Mar 26, 2012 at 3:21 PM.
  3. #3
    Hi spook,

    I've made a full sample demonstrating all functionality of your scenario.

    If you click the "Submit" Button first, a notification Window should appear with "NOTHING HERE".

    Then click the "Call doSomething" Button, then click the "Submit" Button again. A new notification Window should appear with "99".

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">   
        protected void Button2_Click(object sender, Ext.Net.DirectEventArgs e)
        {
            string id = this.Hidden1.Text;
    
    
            X.Msg.Notify("ID", id).Show();
        }
    </script>
    
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    
    
        <script type="text/javascript">
            var doSomething = function (id) {
                Hidden1.setValue(id);
            };
        </script>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <ext:Hidden ID="Hidden1" runat="server" Text="NOTHING HERE" />
        
        <ext:Button ID="Button1" runat="server" Text="Call doSomething" OnClientClick="doSomething(99)" />
    
    
        <ext:Button ID="Button2" runat="server" Text="Submit" OnDirectClick="Button2_Click" />
    </form>
    </body>
    </html>
    Hope this helps.
    Geoffrey McGill
    Founder
  4. #4
    Quote Originally Posted by geoffrey.mcgill View Post
    Hi spook,

    I've made a full sample demonstrating all functionality of your scenario.

    If you click the "Submit" Button first, a notification Window should appear with "NOTHING HERE".

    Then click the "Call doSomething" Button, then click the "Submit" Button again. A new notification Window should appear with "99".

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">   
        protected void Button2_Click(object sender, Ext.Net.DirectEventArgs e)
        {
            string id = this.Hidden1.Text;
    
    
            X.Msg.Notify("ID", id).Show();
        }
    </script>
    
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    
    
        <script type="text/javascript">
            var doSomething = function (id) {
                Hidden1.setValue(id);
            };
        </script>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <ext:Hidden ID="Hidden1" runat="server" Text="NOTHING HERE" />
        
        <ext:Button ID="Button1" runat="server" Text="Call doSomething" OnClientClick="doSomething(99)" />
    
    
        <ext:Button ID="Button2" runat="server" Text="Submit" OnDirectClick="Button2_Click" />
    </form>
    </body>
    </html>
    Hope this helps.

    Okay so this works. And I see why. The piece I was missing was the setText/setValue methods.


    Here's my disconnect:

    Why is the behavior different from setting the value the way I had it before? It is more natural to set the value that way. Why does it only set the value locally but not in a available in the code-behind type of way? This is very confusing.

    Do I have do this for everything? setImage, setHeight, setMargin, setHidden, etc?

    Thanks!
  5. #5
    Quote Originally Posted by Spook View Post
    Why is the behavior different from setting the value the way I had it before?
    Your original code did not work because it was the wrong syntax.

    // Old
    Ext.getCmp('TestId').Text = id;
    On the client, you'll need to use JavaScript, which generally follows the "set*" syntax.

    It is more natural to set the value that way.
    Agreed, but it won't work, so using "set*" syntax is required.

    Why does it only set the value locally but not in a available in the code-behind type of way?
    The sample did not work because the code used was not correct.

    Do I have do this for everything? setImage, setHeight, setMargin, setHidden, etc?
    Yes, if you are using JavaScript.

    Hope this helps.
    Geoffrey McGill
    Founder
  6. #6
    Quote Originally Posted by geoffrey.mcgill View Post
    Your original code did not work because it was the wrong syntax.

    // Old
    Ext.getCmp('TestId').Text = id;
    On the client, you'll need to use JavaScript, which generally follows the "set*" syntax.



    Agreed, but it won't work, so using "set*" syntax is required.



    The sample did not work because the code used was not correct.



    Yes, if you are using JavaScript.

    Hope this helps.
    This helps a lot.

    Last question though, when I do set the value using Control.Text = value; What does it do exactly?

    Because I can pop an alert message afterwards and I see that the value was correctly set. But judging from your responses, even though that I can do it, doesn't mean I should and I would expect issues if I do.

    I guess I am all set. Thanks Geoffrey. Development should be a breeze now since I understand the framework.
  7. #7
    Quote Originally Posted by Spook View Post
    Last question though, when I do set the value using Control.Text = value; What does it do exactly?
    During DirectEvent it generates a respective JavaSctipt to update a client side widget.
  8. #8
    Quote Originally Posted by Daniil View Post
    During DirectEvent it generates a respective JavaSctipt to update a client side widget.
    I meant in Javascript. Why would setting that value in Javascript not propogate to the Direct Event method in C#?
  9. #9
    Quote Originally Posted by Spook View Post
    I meant in Javascript. Why would setting that value in Javascript not propogate to the Direct Event method in C#?
    In the sample I provided the input field value set in JavaScript does propagate correctly to the server-side.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 2
    Last Post: May 10, 2011, 6:32 PM
  2. User Control Topbar is not visible in calendar
    By krishna in forum 1.x Help
    Replies: 2
    Last Post: Jan 07, 2011, 1:01 PM
  3. [CLOSED] Window in a control is visible when page is rendered
    By gokcemutlu in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 15, 2010, 7:05 AM
  4. Datefield Control not visible in a Custom Dialog Box
    By novicefromtexas in forum 1.x Help
    Replies: 0
    Last Post: Oct 22, 2009, 6:52 PM
  5. Replies: 1
    Last Post: Jul 16, 2009, 4:00 AM

Posting Permissions