Change control type at runtime

R

RSH

Hi,

Is it possible to change the type of controls at run-time?

In other words I have a form with TextBoxes etc. on it. If the user only
has readonly privelages I was wondering if I could change the type of
control from TextBox to a Label or something and set the text
programatcially as I would the textbox.

If so how do I do it?

Thanks!
Ron
 
D

David Wier

Check out this code sample at ASPNet101.com:
http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=readonly
It specifically shows how to do what you're talking about.
--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com

Eliyahu Goldin said:
Ron,

Once an object has been created, you can't change it's type. But you can
style a textbox that it will look like a label.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


RSH said:
Hi,

Is it possible to change the type of controls at run-time?

In other words I have a form with TextBoxes etc. on it. If the user only
has readonly privelages I was wondering if I could change the type of
control from TextBox to a Label or something and set the text
programatcially as I would the textbox.

If so how do I do it?

Thanks!
Ron
 
R

RSH

Good stuff...sometimes the solution is easier than you think.

I created a CSS class for readonly and editable and based on the credentials
I switched the class out on the fly. Seems to work pretty slick in my test.

Thanks for the ideas!

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top