Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

Post Serialized Objects (Data) in ASP.NET

, 25 Feb 2013 CPOL
This is helper class to post serialized objects (Data) to other page in asp.net.
PostDataSample-noexe.zip
PostData
PostDataSample.suo
PostDataSample
App_Code
WebUtilities
obj
Properties
PostDataSample.zip
PostDataSample.suo
App_Data
Bin
TripleDESEncryption.dll
WebUtilities.dll
WebUtilities.pdb
bin
Debug
TripleDESEncryption.dll
WebUtilities.dll
WebUtilities.pdb
Debug
ResolveAssemblyReference.cache
TempPE
WebUtilities.dll
WebUtilities.pdb
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using TripleDESEncryption;
namespace WebUtilities
{
    public partial class PostDataHelper
    {
        [Serializable]
        public class PostData : IEnumerable
        {
            private NameValueCollection values = new NameValueCollection();
            /// <summary>
            /// FormName
            /// </summary>
            public string FormName
            {
                get
                {
                    return this.Get("__TransferData").ToString();
                }
                set
                {
                    this.Add("__TransferData", value);
                }
            }
            /// <summary>
            /// Adds object to data collection
            /// </summary>
            /// <param name="key"></param>
            /// <param name="value"></param>
            public void Add(string key, object value)
            {
                if (value != null && value.GetType().IsSerializable)
                {
                    LosFormatter x = new LosFormatter();
                    StringWriter sw = new StringWriter();
                    x.Serialize(sw, value);
                    this.values.Set(key, sw.ToString());
                    return;
                }
                throw new ArgumentException("Invalid object for PostData", "value");
            }
            /// <summary>
            /// Get object from data collection
            /// </summary>
            /// <param name="key"></param>
            /// <returns></returns>
            public object Get(string key)
            {
                string tempValue = this.values[key];
                object result;
                if (tempValue == null)
                {
                    result = null;
                }
                else
                {
                    LosFormatter x = new LosFormatter();
                    StringReader sw = new StringReader(tempValue);
                    result = x.Deserialize(sw);
                }
                return result;
            }
            /// <summary>
            /// ctor
            /// </summary>
            public PostData()
            {
                this.FormName = "DefaultForm";
            }
            /// <summary>
            /// Gets serialized value, i.e.string
            /// </summary>
            /// <param name="key"></param>
            /// <returns></returns>
            internal string GetRawData(string key)
            {
                return this.values[key];
            }
            /// <summary>
            /// Sets serialized value
            /// </summary>
            /// <param name="key"></param>
            /// <param name="value"></param>
            internal void SetRawData(string key, string value)
            {
                this.values[key] = value;
            }
            /// <summary>
            /// Clears all data except FormName
            /// </summary>
            public void Clear()
            {
                string fname = this.FormName;
                this.values.Clear();
                this.FormName = fname;
            }
            /// <summary>
            /// Checks if any value is present at key
            /// </summary>
            /// <param name="key"></param>
            /// <returns></returns>
            public bool HasObjectForKey(string key)
            {
                return !string.IsNullOrEmpty(this.values.Get(key));
            }
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            public IEnumerator GetEnumerator()
            {
                return this.values.GetEnumerator();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ajaynarewade
Systems Engineer TCS
India India
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 25 Feb 2013
Article Copyright 2013 by ajaynarewade
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid