C# and VB.net... don't really go with the java setters/getters
In VB, you do a
Public Property LastName
Set
Me.m_lastName = Value
End Set
Get
return Me.m_lastName
End Get
End Property
where m_lastName is a member variable.
Yeah, stuff "disappears" on the PostBack, you have to be aware of objects
called in Page_Load, aren't around on a button click.
I have a "smart" object holder at my blog:
http://spaces.msn.com/sholliday/ 10/24/2005
that should help if you want to go fancy.
Or learn how to perist items in the Session["mykeyname"] format.
"Adam Sandler" <corn29@excite.com> wrote in message
news:1148585166.324260.179360@g10g2000cwb.googlegr oups.com...[color=blue]
> Hi all,
>
> I hope this is an easy one... Using VWD 2005. When I call my accessor
> method (getName) I always receive an empty string back. Debugging
> shows there should be something there but I cannot figure out where the
> problem is actually occurring.
>
> The first couple of lines of my code behind:
>
> Partial Class _Default
> Inherits System.Web.UI.Page
>
> Dim sName As String ' for getter and setter
>
> Here's my getter and setter:
>
> Function getName()
> Return sName
> End Function
>
> Sub setName(ByVal s As String)
> sName = s
> End Sub
>
> Here's the code which calls the setter:
>
> Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Try
> setName(Me.GridView1.SelectedRow.Cells(2).Text)
> Catch nre As NullReferenceException
> MsgBox("Please select a row.")
> End Try
> End Sub
>
> Lastly, here's some code which calls the getter:
>
> Protected Sub Button4_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button4.Click
> MsgBox(getName())
> End Sub
>
>
> When Button4 is clicked, the message box pops up but there's nothing in
> it... where am I going wrong here?
>
> Thanks!
>[/color]