Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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#


1 Answers

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.

like image 84
Kyle Trauberman Avatar answered Mar 04 '26 04:03

Kyle Trauberman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!