Answered by:
ViewState Property

Question
-
Hi,
VB.NET 2013 | ASP.NET 4.5
I have a website and are exporting most of the code into a seperate DLL file and I need to know how to use the ViewState property in a DLL (not Web Form) as a public shared property. Visual Studio keeps saying I need to add Imports ...Web.UI then it still complains when it's added not only with the accessing the non shared member error because it still complains if the shared keyword is removed.
In a WebForm the code would be:
Public Shared Property MyProperty() As Integer Get If ViewState("SomeName") Is Nothing Then CInt(ViewState("SomeName") = 1) End If Return CInt(ViewState("SomeName")) End Get Set (value As Integer) CInt("SomeName") = value End Set End Property
Any ideas?
<hr> <a href="http://www.crouchie.net" title="Homepage" target="_blank">Homepage</a> | <a href="http://www.casualkiss.com" title="Casual Kiss" target="_blank">Free Dating</a> | <a href="https://www.youtube.com/user/XeNxYFaKiE" title="You Tube Channel" target="_blank"> You Tube Channel</a><br/> Please mark 'as answer' if my solution helped you.
- Moved by Carl Cai Tuesday, July 22, 2014 8:09 AM (from vb) asp.net forum is more dedicated for these issues
Friday, July 18, 2014 8:57 AM
Answers
-
I see only a part, but probably senseless code. An ASP.Net program has no state, it means that all data is removed when it is posted. Therefore the Viewstate has only sense if you first get the viewstate back.
Use the SessionState instead of that, much surer.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate(v=vs.110).aspx
Success
Cor- Edited by Cor Ligthert Friday, July 18, 2014 10:22 AM
- Proposed as answer by Carl Cai Monday, July 21, 2014 1:41 AM
- Marked as answer by Just Karl Monday, July 28, 2014 4:15 PM
Friday, July 18, 2014 9:28 AM -
Viewstate is not going to work for you not in some DLL scenario. If this DLL is sitting on the Web server as part of the ASP.NET solution, then you need to be using a HTTP Session State object that is accessible by the ASP.NET UI and DLL hosted by the Web server to keep state between the two.Friday, July 18, 2014 10:17 AM
-
Hi,
For asp.net issues, I would recommend you post them in asp.net forum to get supports.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Just Karl Monday, July 28, 2014 4:15 PM
Monday, July 21, 2014 1:43 AM
All replies
-
I see only a part, but probably senseless code. An ASP.Net program has no state, it means that all data is removed when it is posted. Therefore the Viewstate has only sense if you first get the viewstate back.
Use the SessionState instead of that, much surer.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate(v=vs.110).aspx
Success
Cor- Edited by Cor Ligthert Friday, July 18, 2014 10:22 AM
- Proposed as answer by Carl Cai Monday, July 21, 2014 1:41 AM
- Marked as answer by Just Karl Monday, July 28, 2014 4:15 PM
Friday, July 18, 2014 9:28 AM -
Viewstate is not going to work for you not in some DLL scenario. If this DLL is sitting on the Web server as part of the ASP.NET solution, then you need to be using a HTTP Session State object that is accessible by the ASP.NET UI and DLL hosted by the Web server to keep state between the two.Friday, July 18, 2014 10:17 AM
-
Hi,
For asp.net issues, I would recommend you post them in asp.net forum to get supports.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Just Karl Monday, July 28, 2014 4:15 PM
Monday, July 21, 2014 1:43 AM