An interface simply and only defines a contract for all inheriting objects. It says, "If you're going to inherit from me, you have to play by my rules and define my properties and methods." It's mainly used in distributed objects. Or objects that someone else is going to use.
My understanding and use of encapsulation is to have a set of classes (class library) to completely manage themselves. They handle all data access, data population and expose methods to manipulate that data. It may not be the true definition, but it's the definition I use.
If you have a simple search field and want to pass the value of that field to another page, I would simply URL encode the variable. About the only thing I see from your example that you might be interested in is a "Utility" class.
Something like this would suffice and I use it all the time.
This is C# and I'm not sure of the VB conversion...
Create a "utility" object that all your ASPX pages can use and add this code
using System;
using System.Web;
using System.Web.UI;
namespace Utilities
{
public static class HTTPUtility
{
public static string SearchString = "searchstr";
// used to return string values from a query string
public static string GetRequestVar(string key)
{
if (HttpContext.Current.Request.QueryString[key] == null) return string.Empty;
return (HttpContext.Current.Request.QueryString[key]);
}
// used to return integer values like ID's
public static int GetRequestVarAsInt(string key)
{
int returnval;
if (string.IsNullOrEmpty(GetRequestVar(key))) return -1;
if (int.TryParse(GetRequestVar(key), out returnval)) return returnval;
return -1;
}
}
}
THis would be for Default.aspx
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Add your normal Page_Load code here
//...
//
}
// Here's the button code
protected void btnSearch_Click(object sender, EventArgs e)
{
if(this.txtSearch.Text.Trim() == string.Empty) this.txtSearch.Text = "No Parameters";
else
{
Response.Redirect("SomeProcessingPage.aspx?" + Utilities.HTTPUtility.SearchString + "=" + this.txtSearch.Text.Trim(), false);
}
}
}
Now, on your processing page... SomeProcessingPage.aspx
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class _SomeProcessingPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Add your normal Page_Load code here
//...
//
ProcessSearch();
}
private void ProcessSearch()
{
string str = Utilities.HTTPUtility.GetRequestVar(Utilities.HTTPUtility.SearchString);
if(str == string.Empty)
{
// They hit this page directly and didn't get redirected here... Do something like kick 'em out
}
else
{
//Add functionality to to process the search request
}
}
}
Is that something you're looking for?
I love boots. It's like midgets hugging my calves...