vb.net encapsulation / interface prob (ASP.NET)

I am new to VB.NET and OO so trying to get to grips with this.

I have an interface in the app_code folder with the following:

Imports Microsoft.VisualBasic
Public Interface ISearch
    Property sKeyword() As String
End Interface


Then on my code_behind file for the master page I have the snippet below.
I want to use the keyword input into txtSearch, I am not sure what the SET value is doing. I intend to use the keyword on another page (search.aspx) to display what was typed.

Does the interface property skeyword hold the value across pages or will i need to use querystring? How do I get the txtSearch to actualyl apply the submitted word to the interface?
Partial Class main
    Inherits System.Web.UI.MasterPage
    Implements ISearch
    Private _keyword As String
 
    Public Property sKeyword() As String Implements ISearch.sKeyword
 
        Get
            If txtSearch.Text.Length < 1 Then
                txtSearch.Text = "Nothing"
            End If
            Return _keyword
        End Get
        Set(ByVal value As String)
            _keyword = value
        End Set
    End Property
 
End Class

Open in new window

LVL 8
LotokAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

REA_ANDREWCommented:
Going across pages I would recommend doing the following:
 Pardon any errors in Syntax as I am in C# :-)

Bu basically you want to persist the value, so I use session here as you want to persist across pages.  This way tou can assign the property value to a text box and it will do the following:
Partial Class main
    Inherits System.Web.UI.MasterPage
    Implements ISearch
    Private _keyword As String
 
    Public Property sKeyword() As String Implements ISearch.sKeyword
 
        Get
            If Session("sKeyword") is Nothing
                Return String.Empty
            Return Session("sKeyword").ToString()
        End Get
        Set(ByVal value As String)
            Session("sKeyword")= value
        End Set
    End Property
 
End Class

Open in new window

0
REA_ANDREWCommented:
Might need a then in that if statement with VB.NET, oops
0
LotokAuthor Commented:
Does that mean  "Private _keyword As String" is not needed?
What is the normal reason for adding that then?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

LotokAuthor Commented:
also one last, possible stupid, question.

How would I pass the txtSearch value into the property.
0
REA_ANDREWCommented:
YourProperty = txtSearch.Text

This would assign the text value of the textbox to your property

and subsequently

txtSearch.Text = YourProperty

goes the opposite.  

And yes you are correct the private variable would not be needed if using session.  You can also use this style of property using

ViewState
Cache
Cookie
Profile
Application
Context

etc...  All are valid in there relevant contexts.

Andrew
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LotokAuthor Commented:
Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.