Reputation: 969
I'm starting to work with interfaces and I really don't understand... The situation is this: there is a webcontrol (called TableControl) which displays a table of items using a repeater. TableControl includes also a line of cursors (first, previous, next, last) that implements paging. The cursors are imported from another webControl (CursorControl). TableControl implements also an interface, in which I declare some method to do paging.
*) CursorControl
public class CursorControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string cursor_value;
public string CursorValue
{
get { return cursor_value; }
set { cursor_value = value; }
}
// Called when cursor is clicked.
protected void lnkClick_Command(object sender, CommandEventArgs e)
{
cursor_value = e.CommandArgument.ToString();
}
}
*) TableControl
public partial class TableControl : System.Web.UI.UserControl, IPageableControl
{
protected void Page_Load(object sender, EventArgs e)
{
if(isPostBack)
{
currentPage = CursorControl.CursorValue;
OtherPage(currentPage);
}
}
public int currentPage;
void IPageableControl.OtherPage(int i)
{
if (i == 0)
currentPage = 2;
else if (i == 1 || i == (-1))
currentPage += i;
else
currentPage = 25;
}
}
*) Interface
public interface IPageableControl
{
// Summary:
// Go to page
void OtherPage(int i);
}
When a user clicks on a cursor I pass the value to TableControl, which should start the method OtherPage. But it doesn't work, it says that OtherPage is not in the current context.
How can I access a method of an interface??
Upvotes: 1
Views: 124
Reputation: 21306
You need to make this line:
void IPageableControl.OtherPage(int i)
into this:
void OtherPage(int i)
The first one is explicit, the second is implicit. (What are the differences?)
By the way, on Visual Studio, when you want to implement an interface, press Ctrl + . (dot) on the interface(s) name and it will ask you how to implement it. It makes it much less tedious because you won't have to type the signatures (method names) by yourself.
Upvotes: 1