Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4019082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:03:43+00:00 2026-05-20T10:03:43+00:00

In ASP.NET WebForms I want to pass arbitrary data from server to client and

  • 0

In ASP.NET WebForms I want to pass arbitrary data from server to client and back again. I am serializing to JSON and have been simply producing JavaScript that creates the object on the client. I have no problem sending data to the server with ajax, but there are situations where I also want to send a Javascript object data back to the server on postbacks. So I guess it needs to be in a hidden field.

A couple general questions about this.

1) What is the best way to do this in terms of minimizing complexity and optimizing space and efficiency? In researching this I discovered Protocol Buffers but there does not seem to be a good C# implementation. I did find one, but it was a couple years old and self-described as buggy so that scared me.

2) If I just pass a JSON string, how can I be sure it will be safe to include as the value for a hidden field? Is there any reason I might not want to do this? I could Base64 encode, but it seems like this adds a lot of overhead. What is considered the best or preferred method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:03:44+00:00Added an answer on May 20, 2026 at 10:03 am

    In the past, I’ve usually done the following:

    1. Created a C# object that I can easily serialize to XML (.Net can do this natively and there are JSON serializers out there as well). (Actually I think .Net may do JSON as well… not sure though)
    2. Take this object and share it with the client via a hidden field or lazy load it on the client via an AJAX request.
    3. The client then parses and manipulates the XML (jQuery can do this) and sends it back to the server via AJAX or a hidden field via a POST.
    4. Lastly I deserialize the XML (or JSON) from the client back into an Object and work with it from there.

    So I’m not sure what you’re trying to gain through encoding, but I think the expense of transforming the object from JSON (or XML) to something smaller is too much overhead for any packaging/shrinking benefit. (Unless your a super high traffic site concerned more about bandwidth usage than server/client side processing.)

    EXAMPLE

    Hopefully this gives you an idea of how to accomplish this. Let me know if you have any more questions.

    <html> 
    <head> 
    </head> 
    <body> 
        <input type="button" id="btnObject" value="Show Object" /> 
        <input type="button" id="btnShowHid" value="Show Hidden Input Value" /> 
        <input type="hidden" id="hidInput" value="" /> 
    </body> 
    </html> 
    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
    <script type='text/javascript' src='https://github.com/douglascrockford/JSON-js/raw/master/json2.js'></script> 
    <script> 
        //Your JSON Object
        var myJSONObject = {"bindings": [ 
                {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}, 
                {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}, 
                {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"} 
            ] 
        }; 
    
        //jQuery Document Ready Event
        $(function(){
             //Get a reference to your hidden field
            var $hidInput = $("#hidInput");
    
            //Use json2.js library to convert the json object to a string
            //and assign it to the hidden input's value
            //NOTE: ASP.NET hidden input control reduces to a hidden input so you can treat them the same.
            $hidInput.val(JSON.stringify(myJSONObject));
    
            //Set up click events to view object and hidden value
            $("#btnShowHid").click(function(){
                alert($hidInput.val());
            });
    
            $("#btnObject").click(function(){
                alert(myJSONObject);
            });
    
        });
    </script> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from ASP.NET Webform and Classic ASP. I want to know what are the
I have an ASP.NET webforms application with a Menu control. How does one hide
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
That's a simple task in ASP.NET WebForms:If you want to show/hide a control all
I am using asp.net webforms; I want to submit a form and keep the
I want to provide status updates during a long-running task on an ASP.NET WebForms
I have an ASP.NET WebForms page with forms authentication. When users create a login,
Hi I have to do a small CMS application in MS ASP.NET using WebForms.
I have a small application developed in ASP.NET 2.0 WebForms. For learning purpose, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.