When I open a RadWindow from within a SharePoint web part (wss 3.0 or SharePoint 2007) and want to have it centered on the browser screen (default behavior), the window is not centered when the bowser has scroll bars and the screen position is scrolled (either vertically or horizontally). When the browser has no scroll bars or the scroll bars are at the top (vertical) and left (horizontal) position however, the window is centered as expected.
When I execute the same code from within a ASP.NET page (not using SharePoint), everything works as expected (scrolled as well as non scrolled). I use the RadAjax 2008 Q2 version of the controls and IE6 or IE7.
This behavior can be simulated using the code below:
Web part (WebPartRadWindow.cs file) :
ASPX page (default.aspx.cs file)
Put the web part on a WSS 3.0 site, reduce the height of the browser window to get a vertical scoll bar, scroll down and click the "Open Window" button : the RadWindow is not centerd (displayed way to low). Do the same with the aspx page : the window is centered correctly.
I also noticed a different behaviour between SharePoint and ASP.NET page when positioning a RadWindow from within client code (moveTo function on window object in javascript):
To see the difference in behavior, uncomment the oWindow.moveTo(0, 0) lines in the web part and the ASP.NET code. Probably the reason for the error in centering has the same origin as the positioning difference.
Is there any solution for having the RadWindow centered correctly in both web parts and ASP.NET pages and controls ? For web parts, I now calculate the top left postion of the window in order to have it centered in client code and use a moveTo, but this is sometimes a little bit awkward.
Kind regards,
Igor De Rycke
When I execute the same code from within a ASP.NET page (not using SharePoint), everything works as expected (scrolled as well as non scrolled). I use the RadAjax 2008 Q2 version of the controls and IE6 or IE7.
This behavior can be simulated using the code below:
Web part (WebPartRadWindow.cs file) :
using System; |
using System.Runtime.InteropServices; |
using System.Web.UI; |
using System.Web.UI.WebControls.WebParts; |
using System.Xml.Serialization; |
using Microsoft.SharePoint; |
using Microsoft.SharePoint.WebControls; |
using Microsoft.SharePoint.WebPartPages; |
using System.Web.UI.WebControls; |
using Telerik.Web.UI; |
namespace WebPartRadWindow |
{ |
[Guid("0fb0a390-4eb4-48ec-9d58-ff546c4f8928")] |
public class WebPartRadWindow : System.Web.UI.WebControls.WebParts.WebPart |
{ |
public WebPartRadWindow() |
{ |
this.ExportMode = WebPartExportMode.All; |
} |
protected override void OnInit(EventArgs e) |
{ |
base.OnInit(e); |
AddScriptManager(); |
AddRadWindowManager(); |
} |
protected override void OnLoad(EventArgs e) |
{ |
base.OnLoad(e); |
AddOpenRadWindowScript(); |
} |
protected override void Render(HtmlTextWriter writer) |
{ |
writer.Write("RadWindow postion test"); |
for (int i = 0; i < 30; i++) |
{ |
writer.WriteBreak(); |
} |
writer.Write("<button onclick='OpenRadWindow();return false;' class='Button'>Open window</button>"); |
} |
private void AddScriptManager() |
{ |
if (ScriptManager.GetCurrent(Page) == null) |
Page.Form.Controls.AddAt(0, new ScriptManager()); |
} |
private void AddRadWindowManager() |
{ |
RadWindowManager windowManager = new RadWindowManager(); |
windowManager.ID = "RadWindowManager1"; |
windowManager.DestroyOnClose = true; |
Page.Form.Controls.Add(windowManager); |
} |
private void AddOpenRadWindowScript() |
{ |
ScriptManager.RegisterStartupScript( this, GetType(), "OpenRadWindow" |
, "function OpenRadWindow()" |
+ "{" |
+ " var oWindow = GetRadWindowManager().getWindowByName('TestWindow');" |
+ " if (oWindow != null)" |
+ " oWindow.close();" |
+ " oWindow = radopen('http://www.telerik.com', 'TestWindow');" |
//+ " oWindow.moveTo(0, 0);" |
+ "}" |
, true); |
} |
} |
} |
ASPX page (default.aspx.cs file)
using System; |
using System.Data; |
using System.Configuration; |
using System.Web; |
using System.Web.Security; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using System.Web.UI.WebControls.WebParts; |
using System.Web.UI.HtmlControls; |
using Telerik.Web.UI; |
public partial class _Default : System.Web.UI.Page |
{ |
protected override void OnInit(EventArgs e) |
{ |
base.OnInit(e); |
AddScriptManager(); |
AddRadWindowManager(); |
} |
protected override void OnLoad(EventArgs e) |
{ |
base.OnLoad(e); |
AddOpenRadWindowScript(); |
} |
protected override void Render(HtmlTextWriter writer) |
{ |
base.Render(writer); |
writer.Write("RadWindow postion test"); |
for (int i = 0; i < 30; i++) |
{ |
writer.WriteBreak(); |
} |
writer.Write("<button onclick='OpenRadWindow();return false;' class='Button'>Open window</button>"); |
} |
private void AddScriptManager() |
{ |
if (ScriptManager.GetCurrent(Page) == null) |
Page.Form.Controls.AddAt(0, new ScriptManager()); |
} |
private void AddRadWindowManager() |
{ |
RadWindowManager windowManager = new RadWindowManager(); |
windowManager.ID = "RadWindowManager1"; |
windowManager.DestroyOnClose = true; |
Page.Form.Controls.Add(windowManager); |
} |
private void AddOpenRadWindowScript() |
{ |
ScriptManager.RegisterStartupScript( this, GetType(), "OpenRadWindow" |
, "function OpenRadWindow()" |
+ "{" |
+ " var oWindow = GetRadWindowManager().getWindowByName('TestWindow');" |
+ " if (oWindow != null)" |
+ " oWindow.close();" |
+ " oWindow = radopen('http://www.telerik.com', 'TestWindow');" |
//+ " oWindow.moveTo(0, 0);" |
+ "}" |
, true); |
} |
} |
Put the web part on a WSS 3.0 site, reduce the height of the browser window to get a vertical scoll bar, scroll down and click the "Open Window" button : the RadWindow is not centerd (displayed way to low). Do the same with the aspx page : the window is centered correctly.
I also noticed a different behaviour between SharePoint and ASP.NET page when positioning a RadWindow from within client code (moveTo function on window object in javascript):
- When you position a RadWindow from an ASP.NET page the coordinates are relative to the HTML document : 0, 0 is the upper left point of the HTML document, even when the document is scrolled (in this case when executing a moveTo(0, 0) part or the whole of the RadWindow is off screen).
- When you execute the same function from a web part the coordinates are relative to the screen (or viewport) not to the HTML document: 0, 0 is the upper left corner of the screen, if the document is scrolled, a moveTo(0, 0) results in a RadWindow that is positioned in the upper left corner of the screen and that is always visible even when the document is scrolled.
To see the difference in behavior, uncomment the oWindow.moveTo(0, 0) lines in the web part and the ASP.NET code. Probably the reason for the error in centering has the same origin as the positioning difference.
Is there any solution for having the RadWindow centered correctly in both web parts and ASP.NET pages and controls ? For web parts, I now calculate the top left postion of the window in order to have it centered in client code and use a moveTo, but this is sometimes a little bit awkward.
Kind regards,
Igor De Rycke