Solved

Serialization Deserialization Control property

Posted on 2010-09-10
7
697 Views
Last Modified: 2013-12-17
Serialization / DeSerialization Question

Experts,

Why can`t I serialize, Something like this? What's the work around?

public string TBoxStr
{
     get
          {
              return textbox1.text;
          }
      set
         {
            textbox1.text = value;
         }
}

I tried something like this too, and it doesn`t work.

private string tboxstr;
public string TBoxStr
{
     get
          {
             tboxstr = textbox1.text;
              return tboxstr;
          }
      set
         {
            tboxstr = value
            textbox1.text = tboxstr;
         }
}

I have no problem Serializing and Deserializing something like this -
private string property;
public string Property
{
     get
          {
              return property;
          }
      set
         {
            property = value
         }
}

I was hoping I could Serialize TBoxStr. What am I missing here?
0
Comment
Question by:San24
7 Comments
 
LVL 6

Assisted Solution

by:tikusbalap
tikusbalap earned 75 total points
ID: 33651345
Try:

private string tboxstr;
public string TBoxStr
{
     get { return textbox1.Text; }
     set {  tboxstr = value; }
}

Set the tboxstr to your textbox after Form's load event.

private void form_load(object sender, EventArgs e)
{
    textbox1.Text = tboxstr;
}


0
 
LVL 3

Expert Comment

by:vusov
ID: 33652346
Do you try to serialize your Form? Actually it cannot be serialized because System.ComponentModel.Component.Site is not serializable. I'v tried to create some other class with TextBox and it serialized fine. Please review my sample, is it exactly what you mean?
WindowsFormsApplication2.zip
0
 

Author Comment

by:San24
ID: 33663115
For some reason I cant seem to upload the compressed project here. I`m getting a SUO file not allowed message. Anyways, here is the main form and the User Cntrl. I`m trying to Serialize and DeSerialize the textbox field in the User Control UC. I can Serialize without any problems, I can look at the value in the file but I run into problems DeSerializing it.

Any help to get me out of this would be greatly appreciated!
Form1.cs
UC.cs
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 75 total points
ID: 33663620
I suggest you to create an intermediate class which will only be used to serialize/deserialize.

Pass an instance of this to Control, and pass out at the time of serializing.
0
 

Author Comment

by:San24
ID: 33663658
@Novice_Novie - The problem is not Serializing, the problem I`m having is the property getting the Text Box value. One way to do is using the Validating or the Leave events and then initializing the property. Not the most efficient way to do it since I have multiple controls on the User Control.
0
 
LVL 3

Accepted Solution

by:
vusov earned 350 total points
ID: 33663929
Please review attachments, it's worked fine for me. I found you missed InitializeComponent(); in the UC(SerializationInfo info, StreamingContext ctxt) constructor.
WindowsFormsApplication2.zip
0
 

Author Comment

by:San24
ID: 33664084
@vusov : You Sir are the man! I didn`t miss the InitializeComponent(), I just didn`t know that was to be used. Didn`t find it any of the examples out there. Let me try this on the main program and then assign the points. Thanks again!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now