[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

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

0
Lotok
Asked:
Lotok
  • 3
  • 3
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
LotokAuthor Commented:
Thanks for your help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now