[CLOSED] Calling Web API and accessing page serialized fields

  1. #1

    [CLOSED] Calling Web API and accessing page serialized fields

    Hi,
    I want to access some page all fields values inside an ASP.NET Web API method as Dictionary, please guide how to achieve that, I want to implement a general purpose code so that ASP.NET Web API should be able to read all fields values passed from client-side as JSON on HttpRequest. This is what I have done so far but the service cannot read any field values of the page. Please guide Thanks

    ASP.NET Web API controller for service myService:
            [ActionName("Test")]
            [AcceptVerbs("POST", "GET")]
            public string Test(HttpRequestMessage requestMessage)
            {
                var values = requestMessage.Content.ReadAsAsync<Dictionary<string, string>>().Result;
                return string.Join(",", values.Values.Select(x => x));
            }
    ASP.NET Page declaration:
    
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server">
            </ext:ResourceManager>
            <div>
                <ext:TextField runat="server" ID="txtName" FieldLabel="Name"  />
                <ext:TextField runat="server" ID="txtEmail" FieldLabel="Email"  />
                <ext:Button ID="btnSave" runat="server" Text="Save">
                    <DirectEvents>
                        <Click
                            Success="console.log(result);"
                            Url="/api/myService/Test"
                            Type="Load"
                            Method="POST"
                            CleanRequest="true"
                            Json="true">
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </div>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jul 23, 2015 at 5:41 AM. Reason: [CLOSED]
  2. #2
    Hi @VSPL,

    Please try to remove Type="Load". Does it help?
  3. #3

    Too long Querystring error

    Hi Daniil,
    Removing "Type = Load" creates big query-string which results this error:

    HTTP Error 404.15 - Not Found
    The request filtering module is configured to deny a request where the query string is too long.
    Please suggest, we are also trying to write our own method to achieve this like:
    var serializeControlValues = function () {
                    // App is object
                    // Convert object to array
                    var arrControls = Object.keys(App).map(function(k) { return App[k] });
    
                    // Filter array and convert to object for json
                    var arrControlsByXType = arrControls.filter(filterType);
                    var objControlWithValue = {};
                    for (var i = 0; i < arrControlsByXType.length; i++) {
                        var cnt=arrControlsByXType[i];
                        if(cnt.xtype=="checkboxfield"){
                            objControlWithValue[cnt.boxLabel]=cnt.value;
                        }else{
                            objControlWithValue[cnt.fieldLabel]=cnt.value;
                        }
                    }
                    //console.log(JSON.stringify(objControlWithValue));
    
                    return JSON.stringify(objControlWithValue);
                };
    And then passing the value return from this function as extra-parameter to our web-api controller method. But instead of writing our own, I want to do it with some native functionalities provided in Ext.Js / Ext.Net, please advise.
  4. #4
    Okay, I need to investigate in details. Could you, please, provide a simple test project to reproduce the problem?
  5. #5

    We have changed our requirement

    Hi Daniil,
    I have changed our approach now instead of calling web api, we have directly calling the direct event so that I can easily get the control values automatically, basically I wanted a general purpose handler in web api which was not working, further I wanted to publish a bus in from web-api method even that also not working, so I ended up placing a global event handler of a button click in my base page which will be execute for all child pages I just need to make sure that button should refer to correct base page event handler name. That will serve our purpose and you may close this thread. Thanks

Similar Threads

  1. calling aspx page in tabpanel
    By hsmukunda in forum 1.x Help
    Replies: 1
    Last Post: Oct 04, 2011, 4:29 PM
  2. [CLOSED] Calling a code-behind function from my aspx page
    By Bert76 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 08, 2011, 3:53 PM
  3. Replies: 1
    Last Post: Mar 11, 2011, 2:54 PM
  4. Replies: 2
    Last Post: Feb 15, 2011, 8:24 PM
  5. [CLOSED] Calling js function from parent page
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 03, 2010, 10:50 AM

Tags for this Thread

Posting Permissions