none
求助,使用modalpopupextender时弹出的窗口无法居中 RRS feed

  • 问题


  •                                                (图1)




                                                         (图2)


    如上图
    当第一次点击添加LinkButton按钮后弹出的Panel如图1是居中的
    当是当我再点击Panel中的添加Button调用OnClick事件更新数据库后
    再次点击窗体中的添加LinkButton弹出后的Panel如图2不再居中显示了

    站点的源文件点击进入下载


    前台页面

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    <style type="text/css">
    <!--
    @import "BoiledFashion.css";
    -->
    </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        
        </div>
            品牌<asp:DropDownList ID="brand" runat="server">
            </asp:DropDownList>
            <asp:LinkButton ID="add_brand" runat="server">添加</asp:LinkButton>
            <asp:Panel ID="panel_brand" BorderStyle="Solid" BorderColor="Gray" BorderWidth="1px" runat="server">
                品牌名称:<asp:TextBox ID="add_brand_name" runat="server"></asp:TextBox><asp:RequiredFieldValidator
                    ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="add_brand_name"></asp:RequiredFieldValidator><br />
                品牌代码:<asp:TextBox ID="add_brand_id" runat="server" MaxLength="2"></asp:TextBox><asp:RequiredFieldValidator
                    ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="add_brand_id"></asp:RequiredFieldValidator><br />
                <asp:Button ID="panel_add_brand" runat="server" Text="添加" OnClick="panel_add_brand_Click" />
                <asp:Button ID="panel_brand_close" runat="server" Text="关闭" /></asp:Panel>
            <cc1:modalpopupextender id="ModalPopup_brand" runat="server" TargetControlID="add_brand" PopupControlID="panel_brand"
                BackgroundCssClass="modalBackground" OkControlID="panel_brand_close" />
        </form>
    </body>
    </html>
    


    后台代码

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    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;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //if (Session["USER_NAME"] == null || Session["USER_NAME"].ToString().Trim().Length == 0)
                //{
                //    Response.Write("<script>alert('您还没有登陆!');</script>");
                //    Response.Redirect("default.aspx");
                //}
                brand.Items.Clear();
                brand.Items.AddRange(new GoodsAction().SearchOutKeyInfo("[BRAND]"));
            }
        }
        protected void panel_add_brand_Click(object sender, EventArgs e)
        {
            String brand_name = add_brand_name.Text.ToString().Trim();
            String brand_id = add_brand_id.Text.ToString().Trim();
    
            int result = new GoodsAction().AddOutKey("brand", brand_id, brand_name);
    
            if (result == 21)
            {
                Response.Write("<script>alert('品牌代码已存在!');</script>");
                add_brand_id.Focus();
                return;
            }
    
            if (result == 22)
            {
                Response.Write("<script>alert('品牌名称已存在!');</script>");
                add_brand_name.Focus();
                return;
            }
    
            if (result == 1)
            {
                Response.Write("<script>alert('添加品牌成功!');</script>");
                brand.Items.Clear();
                brand.Items.AddRange(new GoodsAction().SearchOutKeyInfo("[BRAND]"));
            }
            else
            {
                Response.Write("<script>alert('添加品牌失败!\\n请联系管理员。');</script>");
                return;
            }
        }
    }
    

    富磊
    2009年5月30日 0:53

答案

  • 你输出的的 script 与 ajax 的 script 有冲突,你把弹出消息框换成下面的方式就行了,

    ScriptManager.RegisterStartupScript(this, this.GetType(), "J1", "alert('添加品牌成功!');", true);

    知识改变命运,奋斗成就人生!
    • 已标记为答案 富磊 2009年6月1日 0:27
    2009年5月30日 15:41
    版主