Showing posts with label positioning. Show all posts
Showing posts with label positioning. Show all posts

Wednesday, March 28, 2012

Dynamic DragPanel Positioning

I'm back to revisiting this issue of positioning dynamically generated DragPanels. It has been suggested to use tables for the layout; however, I'm don't know how to go about doing this. Everything is dynamically generated, so the table needs to be as well.

I am using MasterPages and I'm trying to obtain a layout like below for example in my ContentPlaceHolder.

--------------------------------------------------------

Header Section

--------------------------------------------------------
Menu Section |
| Panel1 Panel2 Panel3 Panel 4
|
|
| Panel5 Panel6
|
|
| Panel7 Panel8 Panel9 Panel10
|
|
| Panel11 Panel12 Panel13
|
|

I am using the following code to generate the DragPanels. The number of DragPanels generated depends on the total count in the array.

for (int i = 0; i < portletRptArray.Length; i += 3)
{
// Setup up the Portlet Header Label Label headerLabel =new Label();
headerLabel.ID ="headerLabel" + i.ToString();
headerLabel.BackColor = System.Drawing.Color.Blue;
headerLabel.ForeColor = System.Drawing.Color.White;

if (i == 0)
{
continue;
}
else { headerLabel.Text = portletRptArray[i + 2].ToString(); headerLabel.Width = Unit.Percentage(portletRptArray[i].Length * 2); }// Setup up the Portlet Header Panel headerPanel =new Panel();
headerPanel.ID ="headerPanel" + i.ToString();
headerPanel.BorderColor = System.Drawing.Color.Blue;
headerPanel.Height = Unit.Pixel(20);
headerPanel.Style.Add("cursor","move");
headerPanel.Controls.Add(headerLabel);

// Setup up the Portlet Body Panel pnlBody =new Panel();
pnlBody.ID ="pnlBody" + i.ToString();
pnlBody.BackColor = System.Drawing.Color.LightGray;
pnlBody.BorderColor = System.Drawing.Color.Blue;
pnlBody.ForeColor = System.Drawing.Color.Black;
pnlBody.BorderWidth = 1;
pnlBody.Height = Unit.Pixel(200);
pnlBody.Style.Add("position","absolute");
pnlBody.Style.Add("left", Unit.Pixel(portletRptArray[i].Length * 20).ToString());
pnlBody.Style.Add("top","200px");
pnlBody.Controls.Add(headerPanel);

// Setup the DragPanel Extender AjaxControlToolkit.DragPanelExtender dPanel =new AjaxControlToolkit.DragPanelExtender();
dPanel.ID ="dPanel" + i.ToString();
dPanel.TargetControlID = pnlBody.ID;
dPanel.DragHandleID = headerPanel.ID;

// Add the DragPanels, DragPanel Extender, and PortletPanel to the Page. portletPanel.Controls.Add(pnlBody); portletPanel.Controls.Add(dPanel);this.Form.Controls.Add(pnlBody);
this.Form.Controls.Add(dPanel);
}

Can someone please show me how I can accomplish this with the above code? This has been really frustrating me.Confused

Can anyone help me with this? It may be a simple task, but I'm having a tough time trying to accomplish it.


No one has any ideas about how to do this?


Hi Lspence,

My understanding of your issue is that you want to make the automatically generated Panel shown as what you described above. If I have misunderstood, please feel free to let me know.

Based on my experience, I think the easiest way is add a Table control to your aspx page and make it work as a container for the generated Panel. So now you can use CSS to control its showing position.

Also you can set the Panel's showing position directly on server side. For example,

Panel1.Attributes.CssStyle.Add("position", "absolute");
Panel1.Attributes.CssStyle.Add("left", "100px");
Panel1.Attributes.CssStyle.Add("top", "100px");

Here is thesimilar thread that you can refer to.

I hope this help.

Best regards,

Jonathan


Thanks for the reply Jonathan. I remember my previous thread, I probably should have just continued this there. Anyway, after discussing this approach with a co-worker I realized that a table won't actually work well here. The reason is because the panels will be placed in each cell to achieve the layout, but they are DragPanels, so when they get moved out of the cell the table will become distorted. I was able to implement a small placing algorithm that allows for the desired placement, but it still needs some tweaking.

I do have another question though. Each DragPanel will act like a portlet, so since everything is dynamically generated how can I dynamically generate the mini-tables for each panel?

Here's an example of how one of the DragPanel's might look:

----------
| Sales Percent |
----------
| Total | 8270% |
| North | 580% |
| East | 2390%|
| South | 3200%|
| West | 2100% |
----------


Hi Lspence,

Thanks for sharing your experience. I agree with you that use TableCell to fix the Panel's position is not the best solution in your situation. You can set the Panel's absolute position on server side. Just like my second suggestion. But It's complex, isn't it?

Here is the sample to generate the Table which is use to display the information and the panel is inside the Panel.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { TableRow myTableRow1 = new TableRow(); TableCell tbCell1 = new TableCell(); tbCell1.Text = "Title1"; tbCell1.Style.Add("border-right-style", "none"); myTableRow1.Cells.Add(tbCell1); TableCell tbCell2 = new TableCell(); tbCell2.Text = "Title2"; tbCell2.Style.Add("border-left-style", "none"); myTableRow1.Cells.Add(tbCell2); this.Table1.Rows.Add(myTableRow1); //add loop here; while() state is preferred. TableRow myTableRow2 = new TableRow(); TableCell tbcell3 = new TableCell(); tbcell3.Text = "111"; TableCell tbcell4 = new TableCell(); tbcell4.Text = "222"; tbcell4.Attributes.Add("align", "center"); myTableRow2.Cells.Add(tbcell3); myTableRow2.Cells.Add(tbcell4); this.Table1.Rows.Add(myTableRow2); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:Table ID="Table1" runat="server" Border="1" BorderColor="black" CellPadding="0" CellSpacing="0" Width="50%"> </asp:Table> </form></body></html>

I hope this help.

Best regards,

Jonathan


Thank you Jonathan, this has been very helpful.

Monday, March 26, 2012

DropShadowExtender and positioning

Hello, I just started messing around with the toolkit and started with the DropShadowExtender. I can't, for the life of me, get it to work with various positioning styles. For instance, consider the following simple example:

<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.overall
{
position: relative;
left: 10px;
top: 10px;
;
height: 500px;
background-color: Silver;
}
.above
{
position: absolute;
margin-left: 10px;
margin-top: 10px;
z-index: 2;
width: 200px;
height: 200px;
background-color: Green;
}
.below
{
position: absolute;
top: 0px;
left: 0px;
width: 300px;
height: 200px;
z-index: 1;
background-color: Blue;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div class="overall">
<asp:Panel ID="above" runat="server" CssClass="above">
Here's some text in a box.</asp:Panel>
<cc1:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="above" Opacity=".5" Rounded="true" TrackPosition="true">
</cc1:DropShadowExtender>
<div class="below">This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... </div>
</div>

</form>
</body>
</html>

What could I possibly be doing wrong? These utilities must be able to work with positioned elements, no? Any insight is much appreciated. Thanks!

Anyone? Anyone? Bueller?

I'd really appreciate any insight on this... Looking through the forums, it appears this extender may simply not work with positioned elements. That's a huge disappointment, but I can live with ditching it if it got a firm denial anywhere. However, it seems whenever anyone raises this issue it simply gets ignored. If this extender doesn't work with positioned elements, it would be great to have a release note or known issue added to the documentation to avoid anyone wasting so much time to find out if it works or there is a workaround. Can anyone else at least copy and paste this code and build a project really quickly just to verify that this is not working? As you can see, it's not an enormously complicated bit of CSS, so I'd like to know if anyone is actually using this extender and seeing it work in any sort of good real-world environments. Heck, I'd like to see if anyone can even get it to work in a testing environment. Thanks...


Can someone at least verify that this is not an isolated issue?

Does this control work, or what? Can NOBODY show a working example with positioned elements? Please? Is this a sore subject, am I missing a FAQ somewhere, or what - I find it crazy that nobody can even take the time to respond to this thread...


Hi Tucker973,

As we know DropShadowExtender works based on complex JS and CSS code, so it is not recommanded to attach many CSS. Based on my experience, I suggest that you should put it into a container and then use css to control its position instead of doing this on DropShadowExtender directly.Here is the working sample.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .dropShadowPanel { width:300px; background-color:#5377A9; color:white; font-weight:bold; } .containerPanel { margin-left:200px; margin-top:200px; } </style></head><body> <form id="form2" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Panel ID="container" runat="server" CssClass="containerPanel"> <asp:Panel ID="Panel1" runat="server" CssClass="dropShadowPanel"> <div style="padding:10px"> First Name: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> Last Name: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> </div> </asp:Panel> <ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" BehaviorID="DropShadowBehavior1" TargetControlID="Panel1" Width="5" Rounded="true" Radius="6" Opacity=".75" TrackPosition="true" /> </asp:Panel> </form></body></html>

Best regards,

Jonathan


Interesting, thanks for the reply. It's working a bit better, but I'm still having an issue with the 'shadow' div getting placed way far away regardless of the "width" setting. I'll continue to mess with it though, this is definitely a step in the right direction. Thanks again.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .overall { position: relative; left: 10px; top: 10px; ; height: 500px; background-color: Silver; } .above { position: absolute; margin-left: 50px; margin-top: 50px; z-index: 2; } .aboveinside { width: 200px; height: 200px; background-color: Green; } .below { position: absolute; top: 0px; left: 0px; width: 300px; height: 200px; z-index: 1; background-color: Blue; } </style></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div class="overall"> <div class="above"> <asp:Panel ID="above" runat="server" CssClass="aboveinside"> Here's some text in a box.</asp:Panel> </div> <cc1:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="above" Width="1" Opacity=".5" Rounded="true" TrackPosition="true"> </cc1:DropShadowExtender> <div class="below">This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... </div> </div> </form></body></html>


Hi Tucker973,

<%@. Page Language="C#" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title> <style type="text/css"> .overall {left: 10px; top: 10px; ; height: 500px; background-color: Silver; } .above { position: absolute; margin-left: 50px; margin-top: 50px; z-index: 2; } .aboveinside { width:300px; background-color:#5377A9; color:white; font-weight:bold; } .below { margin-top: 10px; left: 0px; width: 300px; height: 200px; z-index: 1; background-color: Blue; } </style></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div class="overall"> <asp:Panel ID="above" runat="server" CssClass="aboveinside"><div style="padding:10px"> Here's some text in a box.</div> </asp:Panel> <cc1:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="above"Width="5" Opacity=".5" Rounded="true" TrackPosition="true"Radius="6"> </cc1:DropShadowExtender> <div class="below">This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... </div> </div> </form></body></html>

Best regards,

Jonathan

Wednesday, March 21, 2012

DropDownExtender positioning error

If the target control of a DropDownExtender is used in a control or div tag that has absolute, relative or fixed positioning the dropdownlist will incorrectly position below the target control.

The actual context menu will be displayed in the correct place but the hover panel that looks like a standard dropdownlist control will be displayed incorrectly. See the following link for more information and screenshot of the problemhttp://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=10075


Here is an arbitrary example. The real problem is when this control is used in third party grids that make use of relative positioning of some of their outer elements.

Has anybody else encountered this problem? Anybody know how the DropDownExtender javascript/CSS could be updated to correct this issue?

Example code

<div style="position:fixed">
<asp:Label ID="Label2" runat="server" Text="Select action"
Style="display: block; width: 100px; padding:2px; padding-right: 50px;" />
</div
<asp:Panel ID="Panel1" runat="server" CssClass="ContextMenuPanel"
Style="display :none; visibility: hidden;">
<asp:LinkButton runat="server" ID="LB1" Text="Mocha" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="LB2" Text="Java" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="LB3" Text="None" CssClass="ContextMenuItem" />
</asp:Panel
<ajaxToolkit:DropDownExtender runat="server" ID="DropDownExtender1" TargetControlID="Label2" DropDownControlID="Panel1" />

I'm having the same problem. It started after installing the latest build. The problem is not limited to 3rd party controls. Even the slightest modification of the Ajax dropdown example to position the target element creates this problem

Example code: -- same as dropdown example in the AJAX Samples: (For the sample, the problem occurs with either "relative" or "absolute")

<divstyle="position: relative"><asp:LabelID="TextLabel"runat="server"Text="Hover Over Me"Font-Names="Tahoma"Font-Size="11px"Style="display: block; width: 300px; padding:2px; padding-right: 50px;"/></div><asp:PanelID="DropPanel"runat="server"CssClass="ContextMenuPanel"Style="display:none;visibility:hidden;"><asp:LinkButtonrunat="server"ID="Option1"Text="Option 1"CssClass="ContextMenuItem"/><asp:LinkButtonrunat="server"ID="Option2"Text="Option 2"CssClass="ContextMenuItem"/><asp:LinkButtonrunat="server"ID="Option3"Text="Option 3 (Click Me!)"CssClass="ContextMenuItem"/></asp:Panel><ajaxToolkit:DropDownExtenderrunat="server"ID="DDE"TargetControlID="TextLabel"DropDownControlID="DropPanel"/>