user740136
user740136

Reputation:

Dynamic controls in ASP.NET

I've created a Windows Forms Application in C# which allows users to add controls to a TabPage which they can resize and reposition. Now I want to do the same thing only in ASP.NET.

I managed to add the controls dynamically following this tutorial. I use jQuery UI to make them resizable and draggable. The problem I encountered is that when I add a new control all the others are reverted to their initial position and dimension.

I assume I have to save their position and size and apply them to the newly created control on LoadViewState. Is there a way I can view this attributes from code-behind? I've managed to get these info using Javascript but I don't know how to get it into code-behind.

Can someone please point me in the right direction? Thanks in advance.

[EDIT] Thank you for your answers. Here's the code: HTML C#

Upvotes: 3

Views: 572

Answers (1)

Kyle Trauberman
Kyle Trauberman

Reputation: 25694

You need to store the positions and dimensions of the controls and pass those values to the server when you click the add control button.

You have a few options of how to do this.

  • Query String
  • Hidden Form Fields (<input type="hidden">)
  • Hidden Text Box (hidden with style="display: none;")

You can use JavaScript to set these values, then apply the positions in your code behind after adding a new control.

Upvotes: 1

Related Questions