How to add object to script control in VB .NET 2008 Express


I am using Microsof Visual Basic .Net 2008 and Dot Net framework 3.5.

I'm using the following code.

Dim ScriptCntrl as New MSScriptControl.ScriptControlClass
Dim ObjTexbox as new TextBox
ObjTexbox.Name = "txtFirstName"


when I m executing the above code I'm getting following error

"Specified Cast is Not Valid"

What is the solution?

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.

Are you sure that the ScriptContol.AddObject method accepts 3 arguments?  I am looking at the Microsoft page on the Script Control metjods, and AddObject appears to accept 2 (TWO) arguments, the Name (as a string), and the ControlObject, to be identified by that name.
Mike TomlinsonMiddle School Assistant TeacherCommented:
It works for me...after fixing the typos and setting a Language.  The name of the textbox wasn't consistent:

        Dim ScriptCntrl As New MSScriptControl.ScriptControlClass
        ScriptCntrl.Language = "VBScript"

        Dim ObjTextBox As New TextBox
        ObjTextBox.Name = "txtFirstName"

        ScriptCntrl.AddObject(ObjTextBox.Name, ObjTextBox, True)

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
Forced accept.

EE Admin
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
.NET Programming

From novice to tech pro — start learning today.