PDA

View Full Version : [CLOSED] formID with directMethod fails to send dates



aisi_it_admin
Dec 30, 2012, 3:19 PM
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

Baidaly
Dec 30, 2012, 5:36 PM
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>

aisi_it_admin
Dec 30, 2012, 6:04 PM
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?20866-CLOSED-Direct-event-multiple-forms-on-page) - at least that's how I understand that

Thanks

Vladimir
Dec 30, 2012, 7:01 PM
Try to set the same SubmitFormat

aisi_it_admin
Dec 30, 2012, 8:46 PM
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

Baidaly
Dec 31, 2012, 12:36 AM
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/#!/api/Ext.form.field.Date-cfg-submitFormat



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?

aisi_it_admin
Jan 01, 2013, 12:40 PM
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

Daniil
Jan 01, 2013, 1:59 PM
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.



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>