ASP.net ITemplate oroblem

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

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
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 BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
my problem is with ITemplate. It is not recognized even though I have referenced System.Web.UI
it_saigeDeveloperCommented:
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-
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor 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
it_saigeDeveloperCommented:
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-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor 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 BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.