Solved

ViewState?

Posted on 2004-03-23
10
498 Views
Last Modified: 2010-04-15

ViewState["Sql"] = SqlStatement;

load the form ...(dynamically)

submit button...

 reload the form.....(dynamically)

string SQL =(string)ViewState["Sql"]; --> empty ... does view state only work with regular forms or would it work with dinamically recreated forms?


0
Comment
Question by:alain123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10661418
In the Page_Load method:

if (this.IsPostBack)
      Response.Output.Write (ViewState["Sql"]);
else
      ViewState["Sql"] = "test";

It works fine, no problems at all.
0
 
LVL 1

Author Comment

by:alain123
ID: 10661614
how about inside a class.cs after IsPostBack...?
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10661638
How do you access the ViewState from your class.cs?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 1

Author Comment

by:alain123
ID: 10667907
like this

string SQL;
SQL =(string)ViewState["GridSql"];
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10668010
ViewState is not a part of your class, so you cannot access it like this. You have to assign it somehow
0
 
LVL 1

Author Comment

by:alain123
ID: 10682653
tks, avenger.. but somehow how?
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10682719
I don't know. It is not possible to compile the solution if you have just calls to ViewState from a class. You can make it like this:

using System;
using System.Web.UI;
using System.Diagnostics;

class MyClass {
  public StateBag viewState = null;
  ...
  public void SomeMethod () {
    // Do something with the view state
    Trace.WriteLine (this.viewState["SQL"]);
  }
  ...
}

And in the Page_Load:
if (this.IsPostBack) {
    MyClass mc = new MyClass();
    mc.viewState = this.ViewState;
    mc.SomeMethod();
}
else
     ViewState["Sql"] = "test";

0
 
LVL 1

Author Comment

by:alain123
ID: 10708140
hello again Avenger, about this view state issue,

how come i do this on when i load my form ViewState["XMLFORM"] = XMLDocResult.InnerXml;

and on   override protected void OnInit(EventArgs e)
            {

                  InitializeComponent();

                  sSQL = (string)ViewState["XMLFORM"];  --> is null?

(not from inside a class, this is all on the code behnid of the same page)





0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 125 total points
ID: 10708193
Hmm, just a shot (without being sure): as I mentioned to you in a previous post, ASP.NET processes the ViewState AFTER the OnInit of the form. Try to move the code in the Page_Load (you should reattach the Page_Load if you deleted that code) and see if it works there. If it does, consider moving all your initialization code to Page_Load (recommended by all authors/tutorials).
0
 
LVL 1

Author Comment

by:alain123
ID: 10708682
yep, that was it... thanks a lot!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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