How can you move ASP.Net controls to different places on the Web form at runtime?

前端 未结 5 1810
迷失自我
迷失自我 2021-01-01 01:41

Is there an accepted way to \"move\" a control.

My client wants to place a certain chunk of markup (representing some visual element) in one of several different pla

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 02:33

    You could always put panels in the pre-defined locations and add the control to the specific panel at runtime.. Here's an example adding a label (the label could be replaced with any control).

    Dim lblDisplay As Label = New Label()
    lblDisplay.ID = "myLabel"
    lblDisplay.Text = "Some Text"
    pnlDisplay.Controls.Add(lblDisplay)
    

    As far as...

    "Also, I don't want to have to work with this control strictly from the code-behind for the same reason."

    I think you're going to have to do most of your work in the code behind.

    PS.. a good example of the whole usercontrol setup can be downloaded here.. http://www.asp.net/downloads/starter-kits/time-tracker/

提交回复
热议问题