DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   How to call a class (http://www.daniweb.com/forums/thread87692.html)

Danish woman Aug 25th, 2007 4:02 pm
How to call a class
 
I have worked with asp.net for about two month and have not worked with class yet.
I have a form with 10 usercontrols who contains dropdownlists, checkboxes, textboxes and more. My client have to make a dynamic requestform to send out to his members.
This part is working fine.
After the form is sent, I want to save the viewstate in a file, so that the client can access it anytime edit it.

I found the code for saving and loading the viewstate. It is in a class.

Now I don't know how to call the class in the page_load() so that the viewstate is saved and loaded.

This is the class :
public class PersistViewStateToFileSystem : inherits Page

public ViewStateFilePath = server.MapPath("/album/myViewstate.txt")

      Protected Overloads Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)
    ' serialize the view state into a base-64 encoded string
      Dim los as LosFormatter= new LosFormatter()
      Dim writer as StringWriter= new StringWriter()
      los.Serialize(writer, viewState)
      ' save the string to disk
      Dim sw as new StreamWriter(ViewStateFilePath, false)
      sw.Write(writer.ToString())
      sw.Close()
  end sub


        Protected Overloads Overrides Function LoadPageStateFromPersistenceMedium() As Object
    '  determine the file to access
      if NOT File.Exists(ViewStateFilePath)
        return nothing
      else
        ' open the file
        Dim sr as StreamReader= File.OpenText(ViewStateFilePath)
        Dim viewStateString as string = sr.ReadToEnd()
        sr.Close()
        ' deserialize the string
        Dim los as LosFormatter = new LosFormatter()
        return los.Deserialize(viewStateString)
      end if
 end Function
end class

The code is in my aspx page.


All times are GMT -4. The time now is 1:17 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC