[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1265
  • Last Modified:

Override LoadPageStateFromPersistenceMedium in VB code

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", "");

1 Solution
You can compile it into IL code and use reflector(http://www.aisto.com/roeder/dotnet) to decompile it to vb.

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now