How to add user control on run time in ASP.NET?

后端 未结 4 1735
情话喂你
情话喂你 2021-01-18 23:55

How do I add a user control on page load dynamically in ASP.NET?

I have a div with ID=\"contentData\" and few controls

  • one.ascx
  • t
4条回答
  •  情深已故
    2021-01-19 00:48

    I'm a little unclear what you're asking, so forgive me if this doesn't answer the question.

    Assuming the possible values are known in advance and that the number is modest -- like the three in your example -- the easiest thing to do is to include all the controls on the form with "visible=false", then in your Load method set visible to true on the one you want.

    If the number of possibilities is very large, or if it is dynamic so that you don't even know what the possibilities are at coding time, then you could put in a wrapper object, say a div, and add the items to its "controls" property. But I'd avoid this if at all possible because it would be very hard to maintain: future programmers won't even know what controls could possibly be on the screen.

提交回复
热议问题