[CLOSED] Hidden field missing in Form

  1. #1

    [CLOSED] Hidden field missing in Form

    Hello

    Is there a way to send a value of hidden field (TextField) to the server using HttpContext.Current.Request.Form?
    Please examine following code, in the send_form() procedure, Current.Request.Form doesn't contain field1.
    I migrated my code from ext.net 1.7 to 3.2.1 and in 1.x there wasn't such problem.

    test3.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test3.aspx.cs" Inherits="pages_test3" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    test3.aspx.cs:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using Ext.Net;
    using System.Diagnostics;
    
    public partial class pages_test3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          ResourceManager res_man = new ResourceManager();
          res_man.ID = "res_man";
          res_man.IDMode = IDMode.Explicit;
          res_man.ViewStateMode = System.Web.UI.ViewStateMode.Disabled;
          res_man.DirectMethodNamespace = "net";
          form1.Controls.Add(res_man);
    
          Panel panel1 = new Panel();
          panel1.ID = "panel1";
          panel1.LayoutConfig.Add(new TableLayoutConfig() { Columns = 3 });
          panel1.Width = 300;
          panel1.Height = 200;
          form1.Controls.Add(panel1);
    
          TextField field1 = new TextField();
          field1.ID = "field1";
          field1.Value = "Val1";
          field1.Width = 100;
    
          field1.Hidden = true;
          panel1.Items.Add(field1);
    
          Button button1 = new Button();
          button1.Text = "Test";
          button1.Listeners.Click.Handler = "net.send_form();";
    
          panel1.Buttons.Add(button1);
        }
    
    
        [DirectMethod]
        public void send_form()
        {
          string val;
    
          val = Convert.ToString(HttpContext.Current.Request.Form["field1"]);
          Debug.Print(val); //always null when field1 is hidden
        }
    }
    Last edited by pk.net; May 24, 2016 at 10:56 AM.
  2. #2
    Hello @pk.net!

    In the example you are not submitting a form, but calling a direct method -- that's an AJAX request other than an ordinary HTTP POST.

    This does not mean though you can't access data from fields, but means that you have to explicitly send the field as a parameter to the directMethod call. Imagine, if you have a directMethod to check the status of a check-box on your form and you had dozens of textAreas filled with text or even attached files, how slow would that button be? Just needs a check box true/false, but client has to upload the whole form...

    So, if DirectMethod is what you want to analyse this field (and/or other) in the page (not necessarily in the same form), give this example a look, it shows how to properly send parameters using DirectMethod: Events > Direct Method > Overview.

    But maybe what you really want is a full-fledged form submit, here's an example which highlights the feature: Forms > Miscellaneous > Contact Form. Notice that in this example, ContactForm.ascx, JavaScript sendForm() function, the actual submit call is commented out because the form just simulates a form behavior. But the correct code is indicated there.

    Hidden fields should be submit -- as far as inside the form -- as any other form field.

    Hope it helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello fabricio.murta, thanks for your reply.
    In my case I actually need to call a direct-method by AJAX as you mentioned (to save data from form to DB), but I don't know how many fields is placed on the form.
    This functionallity of saving is written in the base class of the Page (inherited from System.Web.UI.Page) and used by many client-pages.
    In version 1.7 of Ext.Net the simplest way, In my opinion, was to get the values of fields from HttpContext.Current.Request.Form which contained all fields, even hidden.
    Now I need to implement something simmilar, maybe by passing array of values in JSON to the direct-method.

    Best regards
    PK
  4. #4
    Hello @pk.net! We're investigating the reasons this changed from 1.x to 3.x and whether there's a way to achieve the previous version's behavior in a feasible manner. Hope to be able to come back to you with a reply soon!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello,

    Since v1 there was a significant and important optimization - hidden components are not rendered. They are rendered first time when shown. It was a huge and very needed optimization since the rendering operation is very heavy. But in your scenario it has an unfortunate implication. The hidden TextField is not rendered and, therefore, there is no an input field to submit to server.

    There is no a setting to turn on the old behavior, but I can suggest to try this override. It emulates the old v1 behavior.

    Ext.form.field.Base.override({
        initComponent: function() {
            if (this.hidden) {
                delete this.hidden;
                this.on("afterrender", function() { this.hide(); });
            }
    
            this.callParent(arguments);
        }
    });
    If it works well, you can go with it for now. But I would recommend to create a ticket to maybe revise the logic at some point in the future.

Similar Threads

  1. Replies: 2
    Last Post: Oct 23, 2014, 5:33 AM
  2. [CLOSED] Form missing elements
    By ATLAS in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 28, 2013, 10:04 AM
  3. [CLOSED] OriginalValue Combobox --> Hidden Form Field
    By CarWise in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 25, 2012, 3:34 PM
  4. [CLOSED] CompositeField - Height missing when form panel rendered hidden
    By craig2005 in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Feb 07, 2011, 2:03 PM
  5. [CLOSED] [1.0] form validation - hidden fields
    By betamax in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 20, 2010, 2:04 PM

Posting Permissions