[CLOSED] formID with directMethod fails to send dates

  1. #1

    [CLOSED] formID with directMethod fails to send dates

    Hello
    Experimenting with direct methods a little and I faced following issue: If DateField.Format is set, the date is not passed to the server. In fact, the date is passed to the server but in d/m/Y format, which fails to be formated on server. This happends only if formId is set, otherwise it works fine
    Here is a code:
    <script>
            function submitMe() {
                Ext.net.DirectMethods.DirectMethod();
            }
            function submitMeFormOnly() {
                Ext.net.DirectMethods.DirectMethod({
                    formId : '<%= testForm.ClientID %>'
                });
            }
        </script>
        
        <ext:TextField runat="server" ID="txtJustForHaveTHereSomethingOutofForm" Text="Dummy"></ext:TextField>
        <ext:FormPanel runat="server" ID="testForm">
            <Items>
                <ext:DateField runat="server" ID="date" FieldLabel="xxx"/>
                <ext:Button ID="Button1" runat="server" Text="Click Direct Event" OnDirectClick="testDirectEvent_click"/>
                
            </Items>
        </ext:FormPanel>
        
        <ext:Button runat="server" Text="Test Direct Method Full Submit" OnClientClick="submitMe()"></ext:Button>
        <ext:Button ID="Button2" runat="server" Text="Test Direct Method Form Only" OnClientClick="submitMeFormOnly()"></ext:Button>
    codebehind:
    protected override void OnLoad(EventArgs e)
        {
            if (IsPostBack == false)
                date.SelectedDate = DateTime.Now;
    
            base.OnLoad(e);
        }
        protected void testDirectEvent_click(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("",date.SelectedDate).Show();
        }
    
        [DirectMethod]
        public void DirectMethod()
        {
            X.Msg.Alert("", date.SelectedDate).Show();
        }
    If the last button is clicked the severdate is DateTime.Min, not the DateTime.Now

    In addition - is it possible to configure directevent to send form data only? (it send "dummy" as well)

    I'm on Ext 2.0

    Thanks
    Last edited by Daniil; Jan 07, 2013 at 1:38 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Do you have form tag in your page markup?

    I've tried following example and it works fine:

    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            if (!X.IsAjaxRequest)
                date.SelectedDate = DateTime.Now;
     
            base.OnLoad(e);
        }
        
        protected void testDirectEvent_click(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("",date.SelectedDate).Show();
        }
     
        [DirectMethod]
        public void DirectMethod()
        {
            X.Msg.Alert("", date.SelectedDate).Show();
        }
    </script>
    
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <script>
                function submitMe() {
                    App.direct.DirectMethod();
                }
                function submitMeFormOnly() {
                    App.direct.DirectMethod({
                        formId : '<%= testForm.ClientID %>'
                    });
                }
            </script>
         
            <ext:TextField runat="server" ID="txtJustForHaveTHereSomethingOutofForm" Text="Dummy"></ext:TextField>
            <ext:FormPanel runat="server" ID="testForm">
                <Items>
                    <ext:DateField runat="server" ID="date" FieldLabel="xxx"/>
                    <ext:Button ID="Button1" runat="server" Text="Click Direct Event" OnDirectClick="testDirectEvent_click"/>
                 
                </Items>
            </ext:FormPanel>
         
            <ext:Button runat="server" Text="Test Direct Method Full Submit" OnClientClick="submitMe()"></ext:Button>
            <ext:Button ID="Button2" runat="server" Text="Test Direct Method Form Only" OnClientClick="submitMeFormOnly()"></ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Hello

    I forgot one important note - I have following in skin file:

    <ext:DateField runat="server" Format="yyyy-MM-dd" />


    so the right version to reproduce the problem is to change format of datefield - like:

    <ext:DateField runat="server" ID="date" FieldLabel="xxx" Format="yyyy-MM-dd"/>

    I don't have a form tag, just form panel, I was told it's enough ( in this thread http://forums.ext.net/showthread.php...-forms-on-page) - at least that's how I understand that

    Thanks
  4. #4
    Try to set the same SubmitFormat
  5. #5
    Ok - works
    Not sure why there are two properties for "the same thing" and why it works fine without "formId" config option

    Can I ask on example above, how to send just form data with the direct event?

    Thanks
  6. #6
    Quote Originally Posted by aisi_it_admin View Post
    Ok - works
    Not sure why there are two properties for "the same thing" and why it works fine without "formId" config option
    There are many properties for DateField as AltFormat, Format and SubmitFormat and all of them are useful in some cases. More information you can read on this page http://docs.sencha.com/ext-js/4-1/#!...g-submitFormat

    Quote Originally Posted by aisi_it_admin View Post
    Can I ask on example above, how to send just form data with the direct event?
    Thanks
    I don't quite understand you, what exactly you want to send?
  7. #7
    Hello
    Ok - I understand that different properties might be usefull in some cases but then I still think the server code is not correct:
    DateFieldBase.LoadPostData

    ...
    DateTime dateTime = DateTime.ParseExact(s, this.Format, (IFormatProvider) this.ResourceManager.CurrentLocale);
    ...

    it uses Format property, not the SubmitFormat or whatever else

    And even more - it works without formId and does not work with formId specified -> so something is possibly wrong here, no?


    To second question
    I have the

    <ext:TextField runat="server" ID="txtJustForHaveTHereSomethingOutofForm" Text="Dummy"></ext:TextField>
    	<ext:FormPanel runat="server" ID="testForm">
    		<Items>
    			<ext:DateField runat="server" ID="date" FieldLabel="xxx"/>
    			<ext:Button ID="Button1" runat="server" Text="Click Direct Event" OnDirectClick="testDirectEvent_click"/>
    			
    		</Items>
    	</ext:FormPanel>
    and when the button is clicked I want to send just datefield data to server, so not the txtJustForHaveTHereSomethingOutofForm data
  8. #8
    Quote Originally Posted by aisi_it_admin View Post
    Hello
    Ok - I understand that different properties might be usefull in some cases but then I still think the server code is not correct:
    DateFieldBase.LoadPostData

    ...
    DateTime dateTime = DateTime.ParseExact(s, this.Format, (IFormatProvider) this.ResourceManager.CurrentLocale);
    ...

    it uses Format property, not the SubmitFormat or whatever else

    And even more - it works without formId and does not work with formId specified -> so something is possibly wrong here, no?
    The problem is the fact that SubmitFormat is used on client only if a FormPanel submits data, i.e. when you set up the formId. On server side, we don't know what way the field was submitted. So, we always use the Format property.

    Quote Originally Posted by aisi_it_admin View Post
    To second question
    I have the

    <ext:TextField runat="server" ID="txtJustForHaveTHereSomethingOutofForm" Text="Dummy"></ext:TextField>
        <ext:FormPanel runat="server" ID="testForm">
            <Items>
                <ext:DateField runat="server" ID="date" FieldLabel="xxx"/>
                <ext:Button ID="Button1" runat="server" Text="Click Direct Event" OnDirectClick="testDirectEvent_click"/>
                
            </Items>
        </ext:FormPanel>
    and when the button is clicked I want to send just datefield data to server, so not the txtJustForHaveTHereSomethingOutofForm data
    Is the TextField is out of <form>, it won't be automatically submitted.

    Or set FormID.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Submit(object sender, DirectEventArgs e)
        {
            
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:TextField ID="TextField1" runat="server" Text="Dummy" />
            <ext:FormPanel ID="FormPanel1" runat="server">
                <Items>
                    <ext:DateField runat="server" ID="date" FieldLabel="xxx"/>
                    <ext:Button runat="server" Text="Submit">
                        <DirectEvents>
                            <Click OnEvent="Submit" FormID="FormPanel1" />
                        </DirectEvents>
                    </ext:Button>
                </Items>
            </ext:FormPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. Razor FormPanel "FormID" missing
    By basder in forum 2.x Help
    Replies: 6
    Last Post: Mar 20, 2012, 2:46 PM
  2. DirectMethod request fails in hosting service
    By chezinho in forum 1.x Help
    Replies: 6
    Last Post: Feb 20, 2012, 9:36 PM
  3. [CLOSED] DirectMethod fails on IIS Default documents
    By anup in forum 1.x Legacy Premium Help
    Replies: 23
    Last Post: Nov 15, 2011, 4:04 PM
  4. Replies: 0
    Last Post: Nov 02, 2011, 8:34 AM
  5. Replies: 7
    Last Post: Mar 09, 2011, 8:15 PM

Posting Permissions