3 Replies - 1162 Views - Last Post: 09 July 2014 - 02:41 PM Rate Topic: -----

#1 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 968
  • Joined: 09-May 09

Add controls to web form at runtime

Posted 09 July 2014 - 02:19 PM

Hi all,

Im new to asp.net (windows forms developer), im trying to create controls at run time within a form. However im the location of the controls are based on the webpage itself and not the form. So depending on screen size the controls are in the wrong location.


        Dim txBoxesArray(10) As TextBox

        Dim xpos = 20
        Dim ypos = 100

        Dim i As Integer = 0
        While i < 10


            txBoxesArray(i) = New TextBox
            txBoxesArray(i).ID = "TextBox1"
            txBoxesArray(i).Style("Position") = "Absolute"
            txBoxesArray(i).Style("Top") = ypos & "px"
            txBoxesArray(i).Style("Left") = xpos & "px"

            test.Controls.Add(txBoxesArray(i))

            ypos = ypos + 100

            i = i + 1

        End While



html
<!--Main Content-->
    <div id="main">
        <form id="test" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Button" />

        </form>
    </div>



There is only on form on the page, I have a test button on the form that kicks off the above code

any help would be great

Is This A Good Question/Topic? 0
  • +

Replies To: Add controls to web form at runtime

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9207
  • View blog
  • Posts: 34,589
  • Joined: 12-June 08

Re: Add controls to web form at runtime

Posted 09 July 2014 - 02:21 PM

Curious - what would be the need to create controls, on a web page, in runtime?
Was This Post Helpful? 0
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 968
  • Joined: 09-May 09

Re: Add controls to web form at runtime

Posted 09 July 2014 - 02:35 PM

Im building a critique based recommender system for my masters project.

I want to display (create) buttons within the scenario as and when I need them. If I don't then the screen space will look cluttered.

Any ideas on dynamic positions at runtime?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9207
  • View blog
  • Posts: 34,589
  • Joined: 12-June 08

Re: Add controls to web form at runtime

Posted 09 July 2014 - 02:41 PM

Seems like a less than efficient way of going about things, but so it goes.

Have you investigated the 'placeholder' control? Drop it where you need it, appropriate CSS, etc and then add there.

http://msdn.microsof...=vs.100%29.aspx
http://msdn.microsof...=vs.100%29.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1