Shopping Cart(0)
|
Lightbox(0)
|
Login
ASP.Net Primer
Submit an Article
Web Hosting
Stock Photos
Web Site Interface Techniques
ASP.Net Primer
Web Application Vs Web Site
Web Site Techniques
Interface Techniques
DataSource Overview
Create a DAL for an ODS
Advanced ObjectDataSource
Adventures in .net Paging
Add Paging to a DataList
Repeater PagedDataSource
Advanced ObjectDataSource
SQL Server Primer
Apply
Common Functions
Cast
Convert
Date Functions
Null Functions
Lower & Upper
Except
Intersect
Pivot
RowNumber & Rank
Software Primer
XML Overview
Name Your Site
Syndicate With RSS
Web Design - Get a Spine!
Security: What Hackers Do
Intro To PHP
CGI: What & How?
Web Marketing
Start a Traffic Virus
Web Site Interface Techniques
ASP.Net tutorial by Barbie Hocking ©2010
Click for Sample Code
As discussed in the
Web Application Vs Web Site Model
article, a Web Site's master pages, web forms, and user controls are not stand-alone classes and thus cannot directly cross-communicate with each other. Interfaces allow full cross-communication between these entities. Interfaces are not difficult to implement. The flexibility they provide makes it worth the additional time it takes to set them up.
Interface Overview
Even though an interface is a defined on a physical file, it can be looked at as a logical interaction point. Since it is an intersection point, it does not contain any processing. Instead, It defines the member signatures of the intersection points. In effect, it is simply defining the syntax of the object. A class implementing an interfaces must include each of its signatures.
An interface is setup similar to a class; however, it uses the Interface descriptor instead of the Class descriptor. Note that the naming standard for interfaces dictates that the first letter of the name begins with 'I'.
Class:
public
class
BasePage
Interface:
public
interface
IInterfaceSample
How does an interface allow web master pages, web forms, and user controls to access each other's public methods and properties? A Web Site creates a dll for all components within a directory which creates a likelyhood that not all web entities exist within the same dll. Interfaces are created in the App_Code directory. All interfaces and class objects reside in the App_Code.dll and as such can be accessed by web entities.
Sample Interface:
namespace
InterfaceTechniques
{
public
interface
IInterfaceSample
{
string
ListSelectedProducts(
bool
bBuy);
}
}
Implementing the interface on a web form:
namespace
InterfaceTechniques
{
using
System;
using
System.Collections.Generic;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
InterfaceSample
:
System.Web.UI.Page
,
IInterfaceSample
{
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
}
#region
IInterfaceSample Members
public
string
ListSelectedProducts(
bool
bBuy)
{
if
(bBuy)
return
"this is a BUY'
;
else
return
"this is a SELL'
;
}
#endregion
}
}
Accessing the interface from child user control:
The child control typecasts the web form control to the interface "IInterfaceSample". The public methods and properties defined in the interface and implemented in the web form control are now accessible.
lblParentMethodResults.Text = ((InterfaceTechniques.
IInterfaceSample
)
this
.Page).ListSelectedProducts(
this
.rbBuy.Checked);
Click for Sample Code
Powered by
www.ezjooz.com