Override LoadPageStateFromPersistenceMedium in VB code

Posted on 2006-05-15
Last Modified: 2008-01-09
I need the following code translate from C# to VB.  Thanx!

protected override object LoadPageStateFromPersistenceMedium()
  LosFormatter format = new LosFormatter();

  int cnt = Convert.ToInt32(Request["__VIEWSTATE0"].ToString());
  StringBuilder s = new StringBuilder();

  for (int i = 1; i <= cnt; i++) {
    s.Append(Request["__VIEWSTATE" + i.ToString()].ToString());

  return format.Deserialize(s.ToString());

protected override void SavePageStateToPersistenceMedium(object viewState)
  LosFormatter format = new LosFormatter();
  StringWriter writer = new StringWriter();
  format.Serialize(writer, viewState);
  StringBuilder s = new StringBuilder(writer.ToString());

  int cnt = 1;
  int left = s.Length;

  while( left > 0 ) {
    //Change to any value other than 1000 as necessary
    int cut = (left > 1000) ? 1000 : left;

    RegisterHiddenField("__VIEWSTATE" + cnt.ToString(),

    s = s.Remove(0,cut);

    left -= cut;

  RegisterHiddenField("__VIEWSTATE0", cnt.ToString());
  RegisterHiddenField("__VIEWSTATE", "");

Question by:thespiceman
    LVL 12

    Expert Comment

    You can compile it into IL code and use reflector( to decompile it to vb.
    LVL 11

    Accepted Solution


    Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
       Dim format As New LosFormatter()
       Dim cnt As Integer = Convert.ToInt32(Request("__VIEWSTATE0").ToString())
       Dim s As New StringBuilder()
       Dim i As Integer
       For i = 1 To cnt
          s.Append(Request(("__VIEWSTATE" + i.ToString())).ToString())
       Next i
       Return format.Deserialize(s.ToString())
    End Function 'LoadPageStateFromPersistenceMedium

    Protected Overrides Sub SavePageStateToPersistenceMedium(viewState As Object)
       Dim format As New LosFormatter()
       Dim writer As New StringWriter()
       format.Serialize(writer, viewState)
       Dim s As New StringBuilder(writer.ToString())
       Dim cnt As Integer = 1
       Dim left As Integer = s.Length
       While left > 0
          'Change to any value other than 1000 as necessary
          Dim cut As Integer = (If left > 1000 Then 1000 Else left) 'ToDo: Unsupported feature: conditional (?) operator.
          RegisterHiddenField("__VIEWSTATE" + cnt.ToString(), s.ToString().Substring(0, cut))
          s = s.Remove(0, cut)
          left -= cut
          cnt += 1
       End While
       cnt -= 1
       RegisterHiddenField("__VIEWSTATE0", cnt.ToString())
       RegisterHiddenField("__VIEWSTATE", "")
    End Sub 'SavePageStateToPersistenceMedium

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now