hello friends
how can i disable view state in vb.net,so that i have the properties of labels as i left,when i return to a page.
i am developing a windows application.
thanks in advance.

Dani AI

Generated

As already said you are building a Windows app — that is the key point. ViewState is an ASP.NET WebForms feature (part of System.Web.UI.Page). It does not exist on Windows Forms (System.Windows.Forms.Form), so trying to wire up a Page.Init or to set an EnableViewState property on a WinForms form will produce errors. ’s link points at web-related discussion, but the solution for a Windows application is to use WinForms state patterns instead of ViewState.

Simple, practical options to preserve label/control values when returning to a form:

  • Keep the same Form instance alive: call Hide() instead of Close() so control properties remain in memory. Reuse the instance to show the same state.
  • Use application/user settings (Properties.Settings) to save simple values and reload them on FormLoad.
  • Keep a central model (a plain data class) and bind controls to it, or copy model values back into controls when showing the form.
  • Serialize a state object to file (XML/JSON) or a database for more complex or cross-session persistence.

Example (VB.NET) showing the user-settings approach:

' Save (e.g., on FormClosing)
Properties.Settings.Default.LastLabelText = Label1.Text
Properties.Settings.Default.Save()

' Restore (e.g., on FormLoad)
Label1.Text = Properties.Settings.Default.LastLabelText

Notes and troubleshooting: verify Project Type in Project Properties — if it really is a WebForms project, use page/control EnableViewState or the page directive; if it is WinForms, use the patterns above. Prefer Hide/Show or an in-memory model for short-lived state; use settings/serialization for persistence across runs. If compile errors persist, post the exact project type and the compiler error message so advice can be targeted.

Recommended Answers

All 2 Replies

Check this link out and see what you can do with it. Hope this helps!

-Chris

i was using this earlier'
Disable the View State in the page.M
Private Sub MyPage_Init_DisableViewState(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub
AND ITS GIVING ERROR ON THE 'init' and 'me.enableviewstate=false'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.