2011-06-19 13 views
0

辞書をViewStateに配置すると、これが表示されます。辞書をViewStateに配置する際の問題

Type 'System.Web.UI.WebControls.Table' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable. 

説明現在のWeb要求の実行中に、未処理の例外が発生しました。エラーの詳細とコード内のどこで発生したのかについては、スタックトレースを参照してください。私が理解しない何

Exception Details: System.Runtime.Serialization.SerializationException: Type 'System.Web.UI.WebControls.Table' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

は、私が...私は私が何serializable..but何かをする必要があることを知って、その例外を取り除くどうやっているのですか?

辞書は以下のようになります。

Dictionary<string, List<DisplayAllQuestionsTable>> tPages; 

DisplayAllQuestionsTableをプログラムでシリアル化する

クラスを生成し、その中にテーブルのWebBrowserコントロールを持っている:あなたがしようとしているよう

[Serializable()] 
    public class DisplayAllQuestionsTable 
    { 
     Table Tmain = new Table(); 
     TableRow threadRow; 
     Label viewsLabel; 
     Label repliesLabel; 
     TableCell qTitle; 
     TableCell qView; 
     TableCell qReplies; 
     TableCell qAvatar; 
     TableCell moderatorDelete; 
     HyperLink q; 
     Label lastPostedBy; 
     TableCell tCellLastPostedBy; 
     Button btnMoveThread; 
     Button btnDeleteThread; 
     TableCell tCellmoderaterControls; 
     Dictionary<string, string[]> allTopics; 
     DropDownList drpDnTopics; 
     DropDownList drpDnsubtopics; 
     AllQuestions page; 
     string Name { get; set; } 
     string ThreadName { get; set; } 
     string Topic { get; set; } 
     string Subtopic { get; set; } 
     int Views { get; set; } 
     int Replies { get; set; } 
     int PageNumber { get; set; } 
     DateTime Time { get; set; } 
     PlaceHolder holder2; 
     public DisplayAllQuestionsTable(AllQuestions formPage, string name, string ThreadTitle, string topic, string subtopics, int views, int replies, int pageNumber, DateTime time, PlaceHolder pholder) 
     { 
      page = formPage; 
      Name = name; 
      ThreadName = ThreadTitle; 
      Topic = topic; 
      Subtopic = subtopics; 
      Views = views; 
      Replies = replies; 
      PageNumber = pageNumber; 
      DateTime Time = time; 
      holder2 = pholder; 
     } 



     public void ExecuteAll() 
     { 
      CreateTable(); 

      feedInformation(); 
      CreateLabels(); 
      InitializeCells(); 
      AddControlsToCells(); 
      if (HttpContext.Current.User.IsInRole("Administrators") || HttpContext.Current.User.IsInRole("Moderators")) 
      { 

       AddModeratorControls(); 
       ManageDropDownList(); 
       initializeManagerControls(); 
       AddModeraterCells(); 
       ModeraterAddCellsToRows(); 
      } 


      AddCellsToRows(); 

      if (HttpContext.Current.User.IsInRole("Administrators") || HttpContext.Current.User.IsInRole("Moderators")) 
      { 

       ModeraterAddCellsToRowsDelete(); 
      } 
      CreateTable(); 
      holder2.Controls.Add(Tmain); 
      // page.Form.Controls.Add(Tmain); 
     } 


     void feedInformation() 
     { 
      /* 
      * Functions: 
      * 1) SQLCommand= find all the question 
      * 2) SQLCommnad= find the view per question 
      * 3) SQLCommand= find the replies per thread 
      * 4) SQLCommand= extract all Users avatars. 
      * 5) Add functions to check the amount of questions. 
      * if too many questions swap pages (add a page button). 
      * 6) The Moderator will have the authority to delete question 
      * and move it to a different place. - New move buttons should be added! 
      * 
      */ 
      q = new HyperLink(); 
      q.Text = ThreadName; 
      q.NavigateUrl = "AnswerQuestion.aspx"; 
      allTopics = new Dictionary<string, string[]>(); 
      allTopics = AllQuestions.AllTopics(); 
     } 

     void AddModeratorControls() 
     { 
      btnMoveThread = new Button(); 
      btnMoveThread.Text = "העבר ל"; 
      btnDeleteThread = new Button(); 
      btnDeleteThread.Text = "מחק"; 

      drpDnTopics = new DropDownList(); 
      drpDnsubtopics = new DropDownList(); 
      drpDnsubtopics.Width = 120; 
      drpDnTopics.AutoPostBack = true; 
      drpDnTopics.SelectedIndexChanged += topicDropDownMenu_SelectedIndexChanged; 
     } 

     void ManageDropDownList() 
     { 

      foreach (var item in allTopics) 
      { 
       drpDnTopics.Items.Add(item.Key); 
      } 
     } 

     void topicDropDownMenu_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      drpDnsubtopics.Items.Clear(); 
      string[] chosenItem = allTopics[drpDnTopics.SelectedItem.Value]; 

      foreach (string item in chosenItem) 
      { 
       drpDnsubtopics.Items.Add(item); 
      } 
     } 

     void CreateLabels() 
     { 
      //Call everytime a question is inserted. 
      viewsLabel = new Label(); 
      repliesLabel = new Label(); 
      lastPostedBy = new Label(); 

      viewsLabel.Text = "צפיות" + "<br/>" + Views; 
      repliesLabel.Text = "תגובות" + "<br/>" + Replies; 
      lastPostedBy.Text = "בעל אשכול" + "<br/>" + Name; 
     } 

     void initializeManagerControls() 
     { 
      tCellmoderaterControls = new TableCell(); 
      moderatorDelete = new TableCell(); 

      tCellmoderaterControls.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right; 
     } 

     void InitializeCells() 
     { 
      //Initialize all controls 
      threadRow = new TableRow(); 
      qTitle = new TableCell(); 
      qView = new TableCell(); 
      qReplies = new TableCell(); 
      qAvatar = new TableCell(); 
      tCellLastPostedBy = new TableCell(); 


      //Adding all controls 
      qTitle.Width = 470; 
      qTitle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right; 
      tCellLastPostedBy.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; 
      qView.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; 
      qReplies.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; 

      qTitle.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Middle; 
      tCellLastPostedBy.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Middle; 
      qView.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Middle; 
      qReplies.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Middle; 
      qTitle.Controls.Add(q); 
     } 

     void AddControlsToCells() 
     { 
      //Call everytime a question in inserted. 

      qReplies.Controls.Add(repliesLabel); 
      qView.Controls.Add(viewsLabel); 
      tCellLastPostedBy.Controls.Add(lastPostedBy); 
     } 

     void AddModeraterCells() 
     { 

      tCellmoderaterControls.Controls.Add(btnDeleteThread); 
      tCellmoderaterControls.Controls.Add(drpDnsubtopics); 
      tCellmoderaterControls.Controls.Add(drpDnTopics); 
      tCellmoderaterControls.Controls.Add(btnMoveThread); 
      moderatorDelete.Controls.Add(btnDeleteThread); 
     } 

     void ModeraterAddCellsToRows() 
     { 
      threadRow.Cells.Add(tCellmoderaterControls); 

     } 

     void AddCellsToRows() 
     { 
      //Call everytime a question is inserted 

      threadRow.Cells.Add(qView); 
      threadRow.Cells.Add(qReplies); 
      threadRow.Cells.Add(tCellLastPostedBy); 
      threadRow.Cells.Add(qAvatar); 
      threadRow.Cells.Add(qTitle); 
      Tmain.Rows.Add(threadRow); 
     } 

     void ModeraterAddCellsToRowsDelete() 
     { 


      threadRow.Cells.Add(moderatorDelete); 
     } 

     void CreateTable() 
     { 
      //Call only once 
      Tmain.Width = 1000; 
      Tmain.BorderColor = System.Drawing.Color.Black; 
      Tmain.BorderWidth = 1; 
      Tmain.CellPadding = 3; 
    } 

} 

答えて

2

辞書ではなくテーブルコントロールをシリアル化しようとしているようです。辞書をテーブルコントロールにバインドしていますか?その場合は、テーブルコントロールではなく辞書をシリアライズしてから、ページロード時にリビルドしてみてください。

+0

ここに私の辞書です、それをシリアル化する方法:[Serializable()] Dictionary > tPages; – Matrix001

+0

DisplayAllQuestionsTableはSystem.Web.UI.WebControls.Table型ですか?表の内容は予測可能で一貫性がありますか?その場合、WebControlをデータコンテナとして渡すのではなく、独自のクラスを作成してデータを保持し、その上にISerializableを実装する方がよいでしょう。 – hermiod

+0

これは単にプログラムによって生成されたテーブルです。テーブルt =新しいテーブル..そしてそれにはもっと多くのものがあります。上記のアップデートをご覧ください: – Matrix001

0

らしいです辞書ではなくWebコントロールをビューステートに保存します。サンプルコードがありますか?

+0

ええ、少し長いです。私が保存しようとしているクラスは、私がプログラムで作成するテーブルを持っています – Matrix001

関連する問題