ASP.NET changing controls order in div - c#

I have two controls in div wrapped into update panel. My code requires for user to be able to change position of second control left,top,right,bottom from first controls point of view. I was thinking of adding a MultiView and adding 4 Views but controls can't have same ID in views and that is essential for my code functionality.
What would be best approach here?

You could add the second control into a placeholder control. See this question : How can you move ASP.Net controls to different places on the Web form at runtime?

Related

Move UserControl to another parent in Page Stack

I have a page of controls that I want to be able to move specific controls by ID to a different parent control server side.
A simple example being another control loads 2 controls vertically ontop of each other. I want a module that can reference those two modules by ID and lay them out horizontally.
I assume this would have to done after the Page_Load() event so that all the controls are loaded.
I think I can accomplish this with a recursive control.FindControl() but I'm thinking there is a more elegant way.
If you plan to dynamically move controls around the page then it’s better to programmatically set them on page where it’s needed.
You should be adding controls in the OnInit method that is run before the page load.
Roughly, the OnInit method would look like
a) check the state of the page and decide where to add control
b) add control where needed

Load User Controls dynamically based on other control events

I have a "cross section" of variables that I need to use to generate a set of user controls dynamically. In the center of the page I have a Telerik multitab/page. I have a custom tree menu and a custom menubar, based on the combination of menu input each of the tabs should load a user control relevant to that cross section of data.
For clarity, almost each tab, treeview, menubar combination needs a unique control.
My problem is that all the postback/loading happens well before the "OnMenuChanged" event triggers, so I'm one "set" of user controls behind. Even if I were to use session/viewstate they wouldn't get assigned until after I needed the value stored in them.
Currently what is happening is the default user controls are loaded in the "pageviewcreated" event, then in the onMenuItemChanged I go back and reload the user controls. It seems very inefficient and is complicating up the approach for selecting the right .ascx.
How do I manage this?
If I understand what you're trying to do could you not use a placeholder control and inject your needed usercontrol into that inside of the events you're managing? Try doing something like this inside of the "OnMenuSelected" event.
WebUserControl1 uc = (WebUserControl1) Page.LoadControl("WebUserControl1.ascx");
PlaceHolder1.Controls.Add(uc);

Create controls dynamically or create controls in a side form? C# winforms

I have a form full of controls, and there is no room for other controls. On the bottom of the form I have a panel with some controls on it.
My goal is that when a certain button is clicked, the original panel on the bottom will be replaced with another panel that contains controls which could be created before the program starts, meaning these controls in the panel do not need to be created dynamically. The replace action would be executed by setting each panel's visible field to it's matched value.
I have thought of two ways of doing this - either creating the new panel (and it's controls) dynamically and adding it to the form instead of the original, or creating the new panel in another form and when the relevant button is clicked the panel being taken from that form and added to the required form (by creating an instance of the new form and making it's panel's modifier public). The "side form"'s purpose is only to create that panel, it has no functionality of it's own.
The advantages of creating the new panel dynamically:
There is no need to create a zero-functionality form.
The advantages of creating the new panel in a side form:
It's very clear which controls are added to the new panel and their positions.
It's very easy to set the location and other fields of the controls in the new panel.
Which way is better?
Thanks!
Have you considered TabControl? That seems a good fit for your needs. Other controls I can think of are StackPanel (Can be fairly easily done for Windows Forms) or OutlookBar like control (again a user control).
Simplest and quickest way seems to be TabControl.
Edit:
SideForm is a different windows form I suppose. So if you are thinking to make controls public and then change their visibility etc, please don't. Use delegates to handle SideForm's events in MainForm.
As you mentioned, there is no room for more controls, I would suggest more screens rather than just one. Having said that I do not know much about your current UI design and functionality so it's up to you.
I would say having the controls hidden and just playing with the Visibility is fine. This means that you do not have to worry about positioning of controls, anchoring and docking at runtime. The problem could well be loading of form. Having huge number of controls having a lot of data associated with them may slow things down.
IMO the best way would be to utilise user controls for this purpose. Simply create one user control per panel you wish to show/hide and place your controls inside. This way you will have both: the designer and the "extra form" you wanted.

I am looking for a specific control panel

I am looking for a specific control panel to contain the 3 gridviews that I have. The user should flip through the gridviews (preferably with no postback). The controls of the flipping should be at the top of the panel. What "control panel" can I use to achieve that aim?
If i understand correctly what you mean with "flip", you could use an ASP.NET Ajax TabContainer to organize the GridViews in different TabPanels. With ASP.NET-Ajax you could also load the TabPanels/GridViews asynchronously and also only if visible.
Here are some tips.
Lazy-Load TabPanels
TabContainer: Tips&Tricks
Well no postback means client side, and there's no better way to do this than with javascript!
If you would consider using jquery/jquery ui, then the ui tabs are probably what you are looking for.
So now you could create a custom control containing all 3 gridviews, and hide/show them using tabs

C# ASP.NET Collapsible Gridview

Is there a way to create a collapsible ASP.NET gridview displaying a parent child relationship based on a check box click?
An easy solution would be to wrap your GridView in an UpdatePanel, and just code everything as you would with normal postbacks. But this is a very heavy-handed approach.
Another option is to use Microsoft's AJAX Library to invoke PageMethods. See the second example here: http://www.asp.net/ajax/documentation/live/Tutorials/ExposingWebServicesToAJAXTutorial.aspx . Once the page loads, you can bind a function to the checkboxes' click events that invokes a PageMethod to inject the appropriate HTML labels and inputs into the row, with a link that passes the values from the form to a different PageMethod.
I don't think that any of the Microsoft grids can do that. However, third party grids will do this. We used ComponentArt's grid control on my last project, and used it to do exactly what you want.

Categories