PC Review


Reply
Thread Tools Rate Thread

Accessing ViewState from Class Lib

 
 
=?Utf-8?B?TmF2bml0?=
Guest
Posts: n/a
 
      5th Feb 2007
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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      5th Feb 2007
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" <(E-Mail Removed)> wrote in message
news:33679D69-464D-40B4-8BEC-(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
=?Utf-8?B?TmF2bml0?=
Guest
Posts: n/a
 
      6th Feb 2007
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" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:33679D69-464D-40B4-8BEC-(E-Mail Removed)...
> > 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
> >

>
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      6th Feb 2007
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" <(E-Mail Removed)> wrote in message
news:8EC4DF70-B73A-4535-BBBD-(E-Mail Removed)...
> 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" wrote:
>
> > 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" <(E-Mail Removed)> wrote in message
> > news:33679D69-464D-40B4-8BEC-(E-Mail Removed)...
> > > 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
> > >

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Viewstate in a Class Vik Microsoft ASP .NET 1 10th Aug 2008 03:01 PM
Viewstate from vb class Chris Microsoft ASP .NET 1 7th Jun 2007 11:27 PM
Accessing ViewState wASP Microsoft C# .NET 6 6th Aug 2005 07:20 AM
ViewState.Add in a Class Lil' Dub Microsoft ASP .NET 4 24th Mar 2004 07:04 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting Microsoft ASP .NET 0 29th Dec 2003 07:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:50 PM.