ASP.net  ITemplate oroblem

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. In my ASP.net web app I  am trying to add the following class but there is a problem with the word "ITemplate". What is this? How can I fix this?

Public Class TemplateHandler
    Implements ITemplate

    Private Sub InstantiateIn(ByVal container As Control)
        Dim cmd As Button = New Button()
        cmd.ID = "cmd"
        cmd.Text = "HI"
        AddHandler cmd.Click, New EventHandler(AddressOf Dynamic_Method)
        container.Controls.Add(cmd)
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You need to specify which method your Sub/Function is implementing in the interface; e.g. -
Class TemplateHandler
    Implements ITemplate

    Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
        Dim cmd As Button = New Button() With {.ID = "cmd", .Text = "HI"}
        AddHandler cmd.Click, AddressOf Dynamic_Method
        container.Controls.Add(cmd)
    End Sub
End Class

Open in new window

-saige-
Murray BrownASP.net/VSTO Developer

Author

Commented:
my problem is with ITemplate. It is not recognized even though I have referenced System.Web.UI

Commented:
As ITemplate has existed in that namespace since .NET 1.1, what is the exact error you are getting?

Have you created your own ITemplate class or related namespace?

-saige-
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Murray BrownASP.net/VSTO Developer

Author

Commented:
If I create a new class called TemplateHandler and the error when I try to debug is "class can inherit only from other classes" I get the following message too
1
Commented:
The error is telling you the same thing I had stated in my first comment.  You must specify which method your Sub/Function (i.e. - InstatntiateIn) is implementing from the interface; e.g. -
Class TemplateHandler
    Implements ITemplate

    Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn '<--- THIS PART HERE
        Dim cmd As Button = New Button() With {.ID = "cmd", .Text = "HI"}
        AddHandler cmd.Click, AddressOf Dynamic_Method
        container.Controls.Add(cmd)
    End Sub
End Class

Open in new window

You can read more about interfaces here: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/interfaces/

-saige-
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks for that. I appreciate your feedback but I have to admit that this sort of code I ridiculous. Microsoft surely could have simplified this
Murray BrownASP.net/VSTO Developer

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial