首页 新闻 搜索 专区 学院

ModalPopupExtender在IE6.0下不居中的问题

0
悬赏园豆:100 [待解决问题]

我把ModalPopupExtender控件和Panel控件都封装到一个自定义控件里面实现了,

然后把这个控件拖到页面上的一个div中,这个div是随竖直滚动条一起滚动的。当弹出ModalPopupExtender的面板后,这个面板不在浏览器的中间,而是跑出浏览器的可见部分了。

该如何解决这个问题,只在IE6.0下有这个问题。

以下为封装的自定义控件

namespace JamesTan.WebControls
{
    using AjaxControlToolkit;
    using JamesTan;
    using JamesTan.Util;
    using SITCAB.Common;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [ToolboxBitmap(typeof(DataGrid)), ToolboxData("<{0}:JamesTanBrowserExtender runat='server'></{0}:JamesTanBrowserExtender>"), Themeable(true)]
    public class JamesTanBrowserExtender : CompositeControl
    {
        private bool allowBinding;
        private bool allowSelectParameters = true;
        private string breadTypeName;
        private ModalPopupExtender browseModalPopupExtender = new ModalPopupExtender();
        private Panel browsePanel = new Panel();
        private Button cancelButton = new Button();
        private Button clearButton = new Button();
        private string controlToExtend;
        private string[] dataFieldItems;
        private string[] dataFormatStrings;
        private string dataObjectTypeName;
        private ObjectDataSource dataSource = new ObjectDataSource();
        private bool enableSelectExXml;
        private GridView GridView1 = new GridView();
        private string[] gridViewDataKeyNames;
        //private GridViewFilterControl gridViewFilterCtrl1 = new GridViewFilterControl();
        private string[] headerTextItems;
        private Button hiddenTargetControl = new Button();
        private Button OkButton = new Button();
        private System.Web.UI.WebControls.PlaceHolder placeHolder;
        private string selectCountMethod = "SelectCount";
        private string selectMethod = "Select";
        private bool showClearButton = false;
        private UpdatePanel UpdatePanel1 = new UpdatePanel();
        private string xmlSchema = "";

        public event BrowseValueSelectedEventHandler BrowseValueSelected;

        public void Browse()
        {
            this.EnsureChildControls();
            this.allowBinding = true;
            this.browseModalPopupExtender.Show();
            this.GridView1.DataBind();
            this.GridView1.SelectedIndex = -1;
            this.OkButton.Enabled = false;
        }

        protected void cancelButton_Click(object sender, EventArgs e)
        {
            this.browseModalPopupExtender.Hide();
        }

        protected void clearButton_Click(object sender, EventArgs e)
        {
            this.browseModalPopupExtender.Hide();
            BrowseValueSelectedArgs args = new BrowseValueSelectedArgs(null);
            if (this.BrowseValueSelected != null)
            {
                this.BrowseValueSelected(this, args);
            }
        }

        protected virtual void ConfigureDataSource(ObjectDataSource ods)
        {
            ods.TypeName = this.breadTypeName;
            ods.DataObjectTypeName = this.dataObjectTypeName;
            ods.SelectMethod = this.SelectMethod;
            ods.SelectCountMethod = this.SelectCountMethod;
            if (!this.AllowSelectParameters)
            {
                ods.SelectParameters.Clear();
                ods.SelectCountMethod = "";
                ods.EnablePaging = false;
                ods.SortParameterName = "";
                this.GridView1.AllowPaging = false;
                this.GridView1.AllowSorting = false;
            }
            if (this.EnableSelectExXml)
            {
                ods.SelectMethod = "SelectExXml";
                ods.SelectCountMethod = "SelectExXmlCount";
                ods.SelectParameters.Insert(0, new Parameter("xmlSchema", TypeCode.String, ""));
            }
        }

        protected virtual void ConfigureGridViewColumns(GridView grid)
        {
            grid.Columns.Clear();
            CommandField field = new CommandField();
            field.ButtonType = ButtonType.Image;
            field.SelectText = "Select";
            field.ShowSelectButton = true;
            field.SelectImageUrl = "~/images/Components/Select.gif";
            grid.Columns.Add(field);
            if (this.dataFieldItems.Length != this.headerTextItems.Length)
            {
                throw new Exception("Error setting DataFieldItems and HeaderTextItems properties.");
            }
            int length = this.dataFieldItems.Length;
            for (int i = 0; i < length; i++)
            {
                BoundField field2 = new BoundField();
                field2.HeaderText = this.headerTextItems[i];
                field2.DataField = this.dataFieldItems[i];
                field2.SortExpression = this.dataFieldItems[i];
                if (this.dataFormatStrings != null)
                {
                    if (this.dataFormatStrings.Length != this.dataFieldItems.Length)
                    {
                        throw new Exception("Error setting DataFormatStrings property.");
                    }
                    if (this.dataFormatStrings[i].StartsWith("{"))
                    {
                        field2.DataFormatString = this.dataFormatStrings[i];
                        field2.HtmlEncode = false;
                    }
                }
                if (this.dataFieldItems[i] == "PK")
                {
                    field2.Visible = false;
                }
                grid.Columns.Add(field2);
            }
            grid.DataKeyNames = this.gridViewDataKeyNames;
        }

        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            this.CreateControlHierarchy();
            this.Initialize();
            base.CreateChildControls();
        }

        protected virtual void CreateControlHierarchy()
        {
            this.hiddenTargetControl.ID = "hiddenTargetControl";
            this.hiddenTargetControl.Attributes["style"] = "display:none";
            this.Controls.Add(this.hiddenTargetControl);
            this.browsePanel.ID = "browsePanel";
            this.browsePanel.Attributes["style"] = "display:none";
            this.browsePanel.ScrollBars = ScrollBars.Auto;
            this.browsePanel.BackColor = Color.White;
            this.browsePanel.Width = Unit.Pixel(600);
            this.Controls.Add(this.browsePanel);
            this.UpdatePanel1.ID = "UpdatePanel1";
            this.UpdatePanel1.UpdateMode = UpdatePanelUpdateMode.Conditional;
            this.browsePanel.Controls.Add(this.UpdatePanel1);
            //this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.gridViewFilterCtrl1);
            //this.gridViewFilterCtrl1.ID = "gridViewFilterCtrl1";
            //this.gridViewFilterCtrl1.EnableColumnFilter = true;
            //this.gridViewFilterCtrl1.GridID = "GridView1";
            //this.gridViewFilterCtrl1.DirectMode = false;
            this.dataSource.ID = "dataSource";
            this.dataSource.DeleteMethod = "Delete";
            this.dataSource.EnablePaging = true;
            this.dataSource.InsertMethod = "Create";
            this.dataSource.OldValuesParameterFormatString = "original_{0}";
            this.dataSource.SelectCountMethod = "SelectCount";
            this.dataSource.SelectMethod = "Select";
            this.dataSource.SortParameterName = "sortby";
            this.dataSource.UpdateMethod = "Edit";
            this.dataSource.SelectParameters.Add(new Parameter("startRowIndex", TypeCode.Int32, "0"));
            this.dataSource.SelectParameters.Add(new Parameter("maximumRows", TypeCode.Int32, "10"));
            this.dataSource.SelectParameters.Add(new Parameter("sortby", TypeCode.String, "{ID}"));
            this.dataSource.SelectParameters.Add(new Parameter("condition", TypeCode.String));
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.dataSource);
            this.GridView1.ID = "GridView1";
            this.GridView1.AllowPaging = true;
            this.GridView1.AutoGenerateColumns = false;
            this.GridView1.DataKeyNames = this.gridViewDataKeyNames;
            this.GridView1.DataSourceID = "dataSource";
            this.GridView1.Width = Unit.Percentage(100);
            this.GridView1.AllowSorting = true;
            this.GridView1.HorizontalAlign = HorizontalAlign.Center;
            this.GridView1.AutoGenerateSelectButton = false;
            this.GridView1.HeaderStyle.BackColor = Color.Gray;
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.GridView1);
            this.placeHolder = new System.Web.UI.WebControls.PlaceHolder();
            this.placeHolder.ID = "placeHolder";
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.placeHolder);
            this.OkButton.ID = "OkButton";
            this.OkButton.Text = "确认";
            this.OkButton.CausesValidation = false;
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.OkButton);
            this.cancelButton.ID = "cancelButton";
            this.cancelButton.Text = "取消";
            this.cancelButton.CausesValidation = false;
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.cancelButton);
            this.clearButton.ID = "clearButton";
            this.clearButton.Text = "清除";
            this.clearButton.CausesValidation = false;
            this.clearButton.ToolTip = "清除";
            this.UpdatePanel1.ContentTemplateContainer.Controls.Add(this.clearButton);
            this.browseModalPopupExtender.ID = "browseModalPopupExtender";
            this.browseModalPopupExtender.PopupControlID = "browsePanel";
            this.browseModalPopupExtender.TargetControlID = "hiddenTargetControl";
            this.browseModalPopupExtender.BackgroundCssClass = "prsModalBackground";
            this.browseModalPopupExtender.RepositionMode = ModalPopupRepositionMode.None;
            this.browseModalPopupExtender.DropShadow = true;
            this.browseModalPopupExtender.Enabled = true;
            this.Controls.Add(this.browseModalPopupExtender);
        }

        protected void dataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!this.allowBinding)
            {
                e.Cancel = true;
            }
            else
            {
                if (!e.ExecutingSelectCount && e.InputParameters.Contains("condition"))
                {
                    //e.InputParameters["condition"] = this.gridViewFilterCtrl1.GetFilterCondition();
                    if (this.Condition != string.Empty)
                    {
                        IDictionary dictionary;
                        object obj2;
                        string str = string.Empty;
                        if (!string.IsNullOrEmpty(e.InputParameters["condition"] as string))
                        {
                            str = " AND ";
                        }
                        str = str + this.Condition;
                        (dictionary = e.InputParameters)[obj2 = "condition"] = dictionary[obj2] + str;
                    }
                }
                if (this.EnableSelectExXml)
                {
                    e.InputParameters["xmlSchema"] = this.XmlSchema;
                }
            }
        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            if (this.GridView1.Rows.Count > 15)
            {
                this.browsePanel.Height = Unit.Pixel(500);
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.allowBinding = true;
            this.GridView1.SelectedIndex = -1;
            this.OkButton.Enabled = false;
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            this.allowBinding = true;
            this.OkButton.Enabled = true;
        }

        protected void GridView1_Sorted(object sender, EventArgs e)
        {
            this.GridView1.SelectedIndex = -1;
            this.OkButton.Enabled = false;
        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            this.allowBinding = true;
        }

        protected void GridViewFilter1_FilterButtonClick(object sender, CommandEventArgs e)
        {
            this.allowBinding = true;
            this.GridView1.SelectedIndex = -1;
            this.OkButton.Enabled = false;
            this.GridView1.DataBind();
        }

        private void iBrowseButton_Click(object sender, EventArgs e)
        {
            this.EnsureChildControls();
            this.OnBrowseButtonClick(sender, e);
        }

        private void Initialize()
        {
            this.GridView1.PageSize = this.PageSize;
            this.ConfigureGridViewColumns(this.GridView1);
            this.ConfigureDataSource(this.dataSource);
            if (!this.showClearButton)
            {
                this.clearButton.Visible = false;
            }
        }

        protected void OkButton_Click(object sender, EventArgs e)
        {
            this.browseModalPopupExtender.Hide();
            BrowseValueSelectedArgs args = new BrowseValueSelectedArgs(this.GridView1.SelectedDataKey);
            this.OnOkButtonClick(this, args);
        }

        protected virtual void OnBrowseButtonClick(object sender, EventArgs e)
        {
            this.allowBinding = true;
            this.browseModalPopupExtender.Show();
            this.GridView1.DataBind();
            this.GridView1.SelectedIndex = -1;
            this.OkButton.Enabled = false;
            this.UpdatePanel1.Update();
        }

        protected override void OnInit(EventArgs e)
        {
            this.SetEventHandler();
            this.SetExternalCtrlClickEventHandler();
            base.OnInit(e);
        }

        protected virtual void OnOkButtonClick(object sender, BrowseValueSelectedArgs e)
        {
            if (this.BrowseValueSelected != null)
            {
                this.BrowseValueSelected(sender, e);
            }
        }

        private void SetEventHandler()
        {
            this.dataSource.Selecting += new ObjectDataSourceSelectingEventHandler(this.dataSource_Selecting);
            this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
            this.GridView1.SelectedIndexChanging += new GridViewSelectEventHandler(this.GridView1_SelectedIndexChanging);
            this.GridView1.Sorting += new GridViewSortEventHandler(this.GridView1_Sorting);
            this.GridView1.Sorted += new EventHandler(this.GridView1_Sorted);
            this.GridView1.DataBound += new EventHandler(this.GridView1_DataBound);
            this.OkButton.Click += new EventHandler(this.OkButton_Click);
            this.cancelButton.Click += new EventHandler(this.cancelButton_Click);
            this.clearButton.Click += new EventHandler(this.clearButton_Click);
            //this.gridViewFilterCtrl1.FilterButtonClick += new CommandEventHandler(this.GridViewFilter1_FilterButtonClick);
        }

        private void SetExternalCtrlClickEventHandler()
        {
            if (!string.IsNullOrEmpty(this.controlToExtend))
            {
                IButtonControl control = FindControlUtility.RecursiveFindControl(this.Parent, this.controlToExtend) as IButtonControl;
                if (control != null)
                {
                    control.Click += new EventHandler(this.iBrowseButton_Click);
                }
            }
        }

        [Browsable(true)]
        public bool AllowSelectParameters
        {
            get
            {
                return this.allowSelectParameters;
            }
            set
            {
                this.allowSelectParameters = value;
            }
        }

        public string BreadTypeName
        {
            set
            {
                this.breadTypeName = value;
            }
        }

        public string Condition
        {
            get
            {
                object obj2 = this.ViewState["BrowserCondition"];
                if (obj2 != null)
                {
                    return (string)obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["BrowserCondition"] = value;
            }
        }

        public string ControlToExtend
        {
            set
            {
                this.controlToExtend = value;
            }
        }

        public string DataFieldItems
        {
            set
            {
                char[] separator = new char[] { ',', ' ' };
                this.dataFieldItems = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            }
        }

        public string DataFormatStrings
        {
            set
            {
                char[] separator = new char[] { ',', ' ' };
                this.dataFormatStrings = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            }
        }

        public string DataObjectTypeName
        {
            get
            {
                return this.dataObjectTypeName;
            }
            set
            {
                this.dataObjectTypeName = value;
            }
        }

        public bool EnableSelectExXml
        {
            get
            {
                return this.enableSelectExXml;
            }
            set
            {
                this.enableSelectExXml = value;
            }
        }

        public string GridViewDataKeyNames
        {
            set
            {
                char[] separator = new char[] { ',', ' ' };
                this.gridViewDataKeyNames = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            }
        }

        [Localizable(true)]
        public string HeaderTextItems
        {
            set
            {
                char[] separator = new char[] { ',' };
                this.headerTextItems = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < this.headerTextItems.Length; i++)
                {
                    this.headerTextItems[i] = this.headerTextItems[i].Trim();
                }
            }
        }

        protected int PageSize
        {
            get
            {
                object obj2 = this.ViewState["PageSize"];
                if (obj2 == null)
                {
                    object propertyValue = HttpContext.Current.Profile.GetPropertyValue("PagingSize");
                    obj2 = ((propertyValue == null) || (propertyValue.ToString() == string.Empty)) ? Globals.PagerSize : propertyValue.ToString();
                    this.ViewState["PageSize"] = obj2;
                }
                return int.Parse((string)obj2);
            }
        }

        protected System.Web.UI.WebControls.PlaceHolder PlaceHolder
        {
            get
            {
                return this.placeHolder;
            }
        }

        public string SelectCountMethod
        {
            get
            {
                return this.selectCountMethod;
            }
            set
            {
                this.selectCountMethod = value;
            }
        }

        public string SelectMethod
        {
            get
            {
                return this.selectMethod;
            }
            set
            {
                this.selectMethod = value;
            }
        }

        public bool ShowClearButton
        {
            set
            {
                this.showClearButton = value;
            }
        }

        public string XmlSchema
        {
            get
            {
                return this.xmlSchema;
            }
            set
            {
                this.xmlSchema = value;
            }
        }

        public delegate void BrowseValueSelectedEventHandler(object sender, BrowseValueSelectedArgs args);
    }
}

 

namespace JamesTan
{
    using System;
    using System.Web.UI.WebControls;

    public class BrowseValueSelectedArgs : EventArgs
    {
        private DataKey gridViewDataKey;

        public BrowseValueSelectedArgs()
        {
        }

        public BrowseValueSelectedArgs(DataKey dataKey)
        {
            this.gridViewDataKey = dataKey;
        }

        public DataKey GridViewDataKey
        {
            get
            {
                return this.gridViewDataKey;
            }
            set
            {
                this.gridViewDataKey = value;
            }
        }
    }
}

 

 

namespace JamesTan.Util
{
    using System;
    using System.Web.UI;

    public class FindControlUtility
    {
        public static Control RecursiveFindControl(Control namingContainer, string controlID)
        {
            Control control = null;
            control = namingContainer.FindControl(controlID);
            if ((control == null) && (namingContainer.NamingContainer != null))
            {
                control = RecursiveFindControl(namingContainer.NamingContainer, controlID);
            }
            return control;
        }

        public static Control RecursiveFindControl(Control namingContainer, Type t)
        {
            Control control = null;
            if (namingContainer.GetType() == t)
            {
                return namingContainer;
            }
            if (namingContainer.Parent != null)
            {
                control = RecursiveFindControl(namingContainer.Parent, t);
            }
            return control;
        }
    }
}

 

 

 

引用该控件的方式如下:

<%@ Register Assembly="JamesTan.WebControls" Namespace="JamesTan.WebControls" TagPrefix="cc1" %>

 <asp:TextBox ID="worktypeTextBox" runat="server" Text='' Enabled="False"></asp:TextBox>
                                    <asp:Button ID="worktypeButton" runat="server" Text="..." Font-Bold="True" />
                                    <cc1:JamesTanBrowserExtender ID="worktypeBrowser" runat="server" BreadTypeName="Siemens.SimaticIT.PRM.Breads.PersonPropertyType_BREAD"
                                        DataFieldItems="ID,Label" DataObjectTypeName="Siemens.SimaticIT.PRM.Breads.Types.PersonPropertyType"
                                        GridViewDataKeyNames="PK,ID,Label" HeaderTextItems="ID,名称" OnBrowseValueSelected="worktypeBrowser_BrowseValueSelected"
                                        ControlToExtend="worktypeButton" Condition=" type=N'工种' " />
                                    <asp:HiddenField ID="worktypeHiddenField" runat="server" Value="0" />

 

亲爱的各位老师,请帮我解决一下这个问题

谭洪星的主页 谭洪星 | 初学一级 | 园豆:102
提问于:2012-08-29 13:24
< >
分享
所有回答(1)
1

设置ModalPopupExtenderPopupDragHandleControlID

shss | 园豆:202 (菜鸟二级) | 2012-08-29 15:24

还是不可以,可能和封装到自定义控件有关系

支持(0) 反对(0) 谭洪星 | 园豆:102 (初学一级) | 2012-09-05 00:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册