473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

creating controls dynamically

This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly above.
How do I/ Can I cast a type to a control?

Nov 21 '05 #1
6 1057
why not using

Me.Controls.Add(o)

"Paul" <pa**@enathan.net> schreef in bericht
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly above.
How do I/ Can I cast a type to a control?

Nov 21 '05 #2

DirectCast should work.

--Robby

"Paul" <pa**@enathan.net> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly above.
How do I/ Can I cast a type to a control?

Nov 21 '05 #3
Neither of these responses work. If you are not certain that something
works, why respond? Many see +'s by these postings and look no further. If
you can run this code and not get any sort of cast exception, then please
respond. Otherwise, please don't waste someone else's time.

DirectCast does not work, nor does Controls.Add(o). Had they tried this they
would know.

"Paul" <pa**@enathan.net> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly above.
How do I/ Can I cast a type to a control?

Nov 21 '05 #4
if you are irritated, don't blame it on the guys who try to help you in
their coffee time!
"Paul" <pa**@enathan.net> schreef in bericht
news:eX**************@TK2MSFTNGP11.phx.gbl...
Neither of these responses work. If you are not certain that something
works, why respond? Many see +'s by these postings and look no further. If
you can run this code and not get any sort of cast exception, then please
respond. Otherwise, please don't waste someone else's time.

DirectCast does not work, nor does Controls.Add(o). Had they tried this
they would know.

"Paul" <pa**@enathan.net> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly
above. How do I/ Can I cast a type to a control?


Nov 21 '05 #5
I agree with Willie. And furthermore, before you post a question be sure
you at least have a BASIC understanding of the .Net Framework.

Why are you trying to cast a Web control to a Form control. I and
apparently Willie also, only checked your syntax not your parameters as we
are not paid to debug your poorly implemented code. Any hobby .Net
programmer knows you can only cast to a type that the object is or has
inherited from. If you took one second out of your busy life to look-up the
Control class and the WebControl class in VS.Net or even MSDN.com instead of
flaming people here that do take time out of their busy lives to help then
maybe you would see the obvious. But that would actually require that you
exercise the few remaining stagnant synapses in your fluid filled globe and
try a little problem solving on your own. So instead you post here and get
frightfully indignant when we have not done all the thinking for you.

Next time solve your own problem. OR be a bit nicer when the community has
left a little work for you to do on your own. After all, it has been
scientifically proven that if you don't use it you will loose it. It is
also true that if you never had it you wont have it unless you go out and
get it.

--Robby
"Willie jan" <un*****@unkown.com> wrote in message
news:41***********************@news.euronet.nl...
if you are irritated, don't blame it on the guys who try to help you in
their coffee time!
"Paul" <pa**@enathan.net> schreef in bericht
news:eX**************@TK2MSFTNGP11.phx.gbl...
Neither of these responses work. If you are not certain that something
works, why respond? Many see +'s by these postings and look no further.
If you can run this code and not get any sort of cast exception, then
please respond. Otherwise, please don't waste someone else's time.

DirectCast does not work, nor does Controls.Add(o). Had they tried this
they would know.

"Paul" <pa**@enathan.net> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly
above. How do I/ Can I cast a type to a control?



Nov 21 '05 #6
I agree with Willie. And furthermore, before you post a question be sure
you at least have a BASIC understanding of the .Net Framework.

Why are you trying to cast a Web control to a Form control. I and
apparently Willie also, only checked your syntax not your parameters as we
are not paid to debug your poorly implemented code. Any hobby .Net
programmer knows you can only cast to a type that the object is or has
inherited from. If you took one second out of your busy life to look-up the
Control class and the WebControl class in VS.Net or even MSDN.com instead of
flaming people here that do take time out of their busy lives to help then
maybe you would see the obvious. But that would actually require that you
exercise the few remaining stagnant synapses in your fluid filled globe and
try a little problem solving on your own. So instead you post here and get
frightfully indignant when we have not done all the thinking for you.

Next time solve your own problem. OR be a bit nicer when the community has
left a little work for you to do on your own. After all, it has been
scientifically proven that if you don't use it you will loose it. It is
also true that if you never had it you wont have it unless you go out and
get it.

--Robby
"Willie jan" <un*****@unkown.com> wrote in message
news:41***********************@news.euronet.nl...
if you are irritated, don't blame it on the guys who try to help you in
their coffee time!
"Paul" <pa**@enathan.net> schreef in bericht
news:eX**************@TK2MSFTNGP11.phx.gbl...
Neither of these responses work. If you are not certain that something
works, why respond? Many see +'s by these postings and look no further.
If you can run this code and not get any sort of cast exception, then
please respond. Otherwise, please don't waste someone else's time.

DirectCast does not work, nor does Controls.Add(o). Had they tried this
they would know.

"Paul" <pa**@enathan.net> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
This was posted yesterday. I needed to post again to clarify my problem.

I'm trying to create control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft .NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly
above. How do I/ Can I cast a type to a control?



Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
6
by: Tex | last post by:
I am writting a survey system web application. I am using ASP.Net 2, C# and MS SQL 2005. I am able to store surveys and questions associated to the surveys just fine. The problem I am having is...
1
by: bill | last post by:
I'm using VS2005. I am dynamically adding a Textbox control to a Placeholder control in the page_load event of the form, but the event handler isn't firing. What am I doing wrong? Thanks...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
3
by: s9213037 | last post by:
Use case scenario: I have a panel with ID "Upload_Panel", where there is a FileUpload control with ID "FileUpload1" and a button with ID "More_Upload_Files", both of which are added at design...
1
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.