Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 what does "MyForm" refer to in Microsoft example

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-21 : 17:29:11
Please I'm trying to learn what enableviewstate does exactly. But I don't know what the MyForm refer to in this example. Whe n I copy the code in my visual studio, it tells me the MyForm doesn't exisit. Check this:

Public Class WebPage
Inherits System.Web.UI.Page
Private myFormObj As MyForm
Private label1 As Label
Private label2 As Label
Private textBoxObj As TextBox
Private buttonObj As Button

Public Sub New()
AddHandler Page.Init, AddressOf Page_Init
End Sub 'New


Private Sub Page_Load(sender As Object, e As System.EventArgs)
' Comment the following line to maintain page view state.
Page.EnableViewState = false
myFormObj.Method = "post"
Controls.Add(myFormObj)
textBoxObj.Text = "Welcome to .NET"

label1.Text = "Enter a name"
buttonObj.Text = "ClickMe"
AddHandler buttonObj.Click, AddressOf Button_Click
myFormObj.Controls.Add(label1)
myFormObj.Controls.Add(textBoxObj)
myFormObj.Controls.Add(buttonObj)
myFormObj.Controls.Add(label2)
End Sub 'Page_Load

Private Sub Button_Click(sender As Object, e As EventArgs)
Dim temp As [String] = "<br>Name is " + textBoxObj.Text + "<br>"
temp += "Saved content of previous page is " + CType(ViewState("name"), String)
label2.Text = temp
End Sub 'Button_Click

Protected Overrides Sub LoadViewState(viewState As Object)
If Not (viewState Is Nothing) Then
MyBase.LoadViewState(viewState)
End If
End Sub 'LoadViewState

Protected Overrides Function SaveViewState() As Object
ViewState("name") = textBoxObj.Text
Return MyBase.SaveViewState()
End Function 'SaveViewState

Private Sub Page_Init(sender As Object, e As EventArgs)
AddHandler Me.Load, AddressOf Me.Page_Load
myFormObj = New MyForm()
label1 = New Label()
label2 = New Label()
textBoxObj = New TextBox()
buttonObj = New Button()
End Sub 'Page_Init
End Class 'WebPage

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-21 : 19:45:49
I believe MyForm in this instance is referring to the name of the html form.

<form ID="MyForm">

if you have named it something else, then change the name in the code behind to match.

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-05-21 : 20:49:54
1/ the weird thing, when I create a new aspx page, where the form ID is Form1 in the html view of the page in my Visual Studio. But, When I do F7 and go to the code behing the page, I can't find Form1 at all
Have u noticed that? so I have no idea what MyFom in Microsoft example above refers to.

2/ Do you have a little example with a line of code that I should comment in order to understand the impact of changing Enableviewstate property of the page. I mean an example of code that changes the behaviour of the page when I change the value of EnableViewState property.

I thank you.
Go to Top of Page
   

- Advertisement -