ViewState.Add in a Class

  • Thread starter Thread starter Lil' Dub
  • Start date Start date
L

Lil' Dub

How can I add to ViewState from a Class. I've inherited Page (tried Control
as well) and then call:

ViewState.Add("ITEM", "VALUE");

but when I try Response.Write((String) ViewState["ITEM"]) I get nothing.

Thanks.
 
I wouldn't even try. This seems to me to break the rules of encapsulation
and would not be good class design.

It seems that your class would be used in a web form (ASP.NET) environment,
so why not just add to viewstate from the page that the class was
instantiated on?

Also, your Response.Write statement below does not include a concatenation
character between the two output values. It should be:

Response.Write((String) & ViewState("ITEM"))
 
I actually have to disagree with Scott on the concatenation portion...he's casting to type string, not concatenating. Though I feel Scott is right on the ViewState design. What purpose are you using this class for? More info would be helpful.

Matt Hawley, MCAD .NET
http://www.eworldui.net

nntp://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet/<[email protected]>

I wouldn't even try. This seems to me to break the rules of encapsulation
and would not be good class design.

It seems that your class would be used in a web form (ASP.NET) environment,
so why not just add to viewstate from the page that the class was
instantiated on?

Also, your Response.Write statement below does not include a concatenation
character between the two output values. It should be:

Response.Write((String) & ViewState("ITEM"))


Lil' Dub said:
How can I add to ViewState from a Class. I've inherited Page (tried Control
as well) and then call:

ViewState.Add("ITEM", "VALUE");

but when I try Response.Write((String) ViewState["ITEM"]) I get nothing.

Thanks.



[microsoft.public.dotnet.framework.aspnet]
 
Oh, I didn't realize that casting is what that was (must be c#). I thought
it was a string value followed by the viewstate value.


Matt Hawley said:
I actually have to disagree with Scott on the concatenation portion...he's
casting to type string, not concatenating. Though I feel Scott is right on
the ViewState design. What purpose are you using this class for? More info
would be helpful.
nntp://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet/ said:
I wouldn't even try. This seems to me to break the rules of encapsulation
and would not be good class design.

It seems that your class would be used in a web form (ASP.NET) environment,
so why not just add to viewstate from the page that the class was
instantiated on?

Also, your Response.Write statement below does not include a concatenation
character between the two output values. It should be:

Response.Write((String) & ViewState("ITEM"))


Lil' Dub said:
How can I add to ViewState from a Class. I've inherited Page (tried Control
as well) and then call:

ViewState.Add("ITEM", "VALUE");

but when I try Response.Write((String) ViewState["ITEM"]) I get nothing.

Thanks.



[microsoft.public.dotnet.framework.aspnet]
 
My idea is to create a class that reads the configuration of a form from an
XML file. Some elements of the form need to be hidden (like the recipient of
the generated email). Now, like other elements of the form, I could
dynamically create control (like HtmlInputHidden), but I'd rather it be in
ViewState so it can't be read easily.



Matt Hawley said:
I actually have to disagree with Scott on the concatenation portion...he's
casting to type string, not concatenating. Though I feel Scott is right on
the ViewState design. What purpose are you using this class for? More info
would be helpful.
nntp://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet/ said:
I wouldn't even try. This seems to me to break the rules of encapsulation
and would not be good class design.

It seems that your class would be used in a web form (ASP.NET) environment,
so why not just add to viewstate from the page that the class was
instantiated on?

Also, your Response.Write statement below does not include a concatenation
character between the two output values. It should be:

Response.Write((String) & ViewState("ITEM"))


Lil' Dub said:
How can I add to ViewState from a Class. I've inherited Page (tried Control
as well) and then call:

ViewState.Add("ITEM", "VALUE");

but when I try Response.Write((String) ViewState["ITEM"]) I get nothing.

Thanks.



[microsoft.public.dotnet.framework.aspnet]
 
Back
Top