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

Who is Participating?
TornadoVConnect With a Mentor Commented:

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
You can compile it into IL code and use reflector(http://www.aisto.com/roeder/dotnet) to decompile it to vb.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.