Accessing ViewState from Class Lib

G

Guest

Hi,

I have the following scenario:-
1) I have a web part
2) This web part uses a class library
3) In the Class Library I want to save and retrieve values from the ViewState

I am not able to do this since ViewState is always associated to a control.
What are the possible options with which I can achieve this?. I don’t want to
pass the instance of the web part in the class lib.

Thanks in advance
 
G

Guest

Hi Eliyahu,

Thanks for the reply.

I have one doubt with respect to the solution just provided:-

1) Web parts would developed independent of each other by developer and then
assembled on the page
2) If 2 developers of the web part coincidently have the same key for
storing values in web part

Wouldent that cause an issue?

One solution I can think of is each developer provide a prefix for the key’s
they use.

Is there a better way out caus we are now relying on the developer to
provide unique keys, which may not always be done :) ?

Thanks again for the reply.

Eliyahu Goldin said:
HttpContext.Current.CurrentHandler will give you a reference to the
currently running page. Once you have the page, you can use it's ViewState.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Navnit said:
Hi,

I have the following scenario:-
1) I have a web part
2) This web part uses a class library
3) In the Class Library I want to save and retrieve values from the
ViewState

I am not able to do this since ViewState is always associated to a
control.
What are the possible options with which I can achieve this?. I don't want
to
pass the instance of the web part in the class lib.

Thanks in advance
 
E

Eliyahu Goldin

Well, the original question was just about accessing the viewstate and your
new questions will apply for any solution.

I am not familiar much with webparts. If they provide a sort of unique id,
you could use this id as the prefix. In any case you may want to make a
utility method that will access the viewstate in the way you wish.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Navnit said:
Hi Eliyahu,

Thanks for the reply.

I have one doubt with respect to the solution just provided:-

1) Web parts would developed independent of each other by developer and then
assembled on the page
2) If 2 developers of the web part coincidently have the same key for
storing values in web part

Wouldent that cause an issue?

One solution I can think of is each developer provide a prefix for the key 's
they use.

Is there a better way out caus we are now relying on the developer to
provide unique keys, which may not always be done :) ?

Thanks again for the reply.

Eliyahu Goldin said:
HttpContext.Current.CurrentHandler will give you a reference to the
currently running page. Once you have the page, you can use it's ViewState.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Navnit said:
Hi,

I have the following scenario:-
1) I have a web part
2) This web part uses a class library
3) In the Class Library I want to save and retrieve values from the
ViewState

I am not able to do this since ViewState is always associated to a
control.
What are the possible options with which I can achieve this?. I don't want
to
pass the instance of the web part in the class lib.

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top