早上好,
我有一个很奇怪的问题。我使用Visual Studio 2013创建了一个ASP项目,并插入了一个简单的GridView。然后,我添加了一个按钮,使我可以使用另一个aspx页面打开模式窗口。问题在于,当打开模式窗口时,父页面中的gridview会更改布局。这是代码:

Home.aspx

<form id="form1" runat="server">
<div>

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

</div>
    <asp:GridView ID="GridView1" runat="server"  CssClass="table table-hover table-striped" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="GymSessionID" HeaderText="ID" />
            <asp:BoundField DataField="SessionDate" HeaderText="Date" />
        </Columns>
    </asp:GridView>
</form>





Home.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
            TestSimoneEntities ent = new TestSimoneEntities();
            GridView1.DataSource = ent.GymSession.ToList();
            GridView1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        string script = @"<script language='javascript'>javascript: window.open('http://www.microsoft.com', null, 'scrollbars=1,width=600,HEIGHT=400');</script>";
        Response.Write(script.ToString());
    }


Dialog.aspx

<form id="form1" runat="server">
<div>

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>


Dialog.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {


        string script = @"<script>

    window.onunload = refreshParent;
    function refreshParent() {
        var loc = window.opener.location;
        window.opener.location = loc;

    }
</script>";
        Response.Write(script.ToString());

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "text";
    }
}


如您所见,代码确实很简单,但是gridview更改了布局

最佳答案

对于谁感兴趣,我解决了这个问题。
我唯一更改的是此行:

字符串脚本= @“ javascript:window.open('http://www.microsoft.com',null,'scrollbars = 1,width = 600,HEIGHT = 400');”;“;
        Response.Write(script.ToString());

到这个:

Page.ClientScript.RegisterStartupScript(
    GetType(),
    “我的钥匙”,
    “ window.open('http://www.microsoft.com',null,'scrollbars = 1,width = 600,HEIGHT = 400');”,“
    真正);

我真的不明白为什么会这样,但是我以这种方式解决了我的问题。

关于javascript - 打开模式对话框时的Asp Gridview更改布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28108816/

10-16 20:33