Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

possible to change the webcontrol type?

Status
Not open for further replies.

g2000

Programmer
Aug 31, 2005
39
US
Is that possible to change the WebControls type?

I have a control. With spaghetti code, I can change to either textbox or label. but no clue how to do it in .NET. anyone?
 
Can you explain further? That doesn't make any sense to me.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
You can't say, take a textbox, now make it a label. There is not conversion possible for that. Is that what you are trying to do?
 
yeah.. jbenson001.. sort of.. but since both control belongs to System.Web.UI.WebControls namespace.

So, I would like .. instead of
<asp:TextBox ... > or <asp:Label ... >

Can I <asp:WebControls ... > ? And set the specific type in
Page_Load or Page_PreRender ???
 
You can have your own custom control that renders either a child Label or TextBox based on some property, but there's no native control to do either/or.

Within a DataGrid or other tempated control, you can also tweak the item templates to conditionally show Labels or Textboxes.
 
You'd want to add a PlaceHolder control to the spot you want to conditionally display the TextBox/Label, then conditionally add either to the PlaceHolder's child controls in Page_Load.
 
Sounds like BoulderBum is suggesting adding dynamic controls at run time. Is this what you want to do? If so, add them in the Page_Init event.
 
That's assuming he knows the condition that determines the control type by Page_Init. :)
 
While I'm thinking about it, another popular (though less efficient) alternative is to add a TextBox and Label side-by-side then set the visibility of the controls conditionally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top