Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Asp Gridview在打开模式对话框时更改布局_Javascript_C#_Asp.net_Gridview_Visual Studio 2013 - Fatal编程技术网

Javascript Asp Gridview在打开模式对话框时更改布局

Javascript Asp Gridview在打开模式对话框时更改布局,javascript,c#,asp.net,gridview,visual-studio-2013,Javascript,C#,Asp.net,Gridview,Visual Studio 2013,早上好, 我有一个很奇怪的问题。我使用Visual Studio 2013创建了一个ASP项目,并插入了一个简单的GridView。然后我添加了一个按钮,允许我用另一个aspx页面打开一个模式窗口。问题是,当打开模式窗口时,父页面中的gridview会更改布局。代码如下: Home.aspx <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" OnCl

早上好, 我有一个很奇怪的问题。我使用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>
<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>

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());
    }
    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";
    }
}
受保护的无效页面加载(对象发送方,事件参数e)
{
TestSimoneEntities ent=新的TestSimoneEntities();
GridView1.DataSource=ent.GymSession.ToList();
GridView1.DataBind();
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
字符串脚本=@“javascript:window.open('http://www.microsoft.com“,null,'滚动条=1,宽度=600,高度=400';”;
Response.Write(script.ToString());
}
Dialog.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>
<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)
    {
            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());
    }
    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";
    }
}
受保护的无效页面加载(对象发送方,事件参数e)
{
字符串脚本=@“
window.onunload=refreshParent;
函数refreshParent(){
var loc=窗口打开器位置;
window.opener.location=loc;
}
";
Response.Write(script.ToString());
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
标签1.Text=“Text”;
}
}

正如您所看到的,代码非常简单,但是gridview更改了布局

对于感兴趣的人,我解决了这个问题。 我唯一改变的是这句话:

字符串脚本=@“javascript:window.open(“”,null,'滚动条=1,宽度=600,高度=400');”; Response.Write(script.ToString())

为此:

Page.ClientScript.RegisterStartupScript( GetType(), “我的钥匙”, “window.open('',null,'滚动条=1,宽度=600,高度=400');”, 正确的)

我真的不明白为什么会发生这种情况,但通过这种方式我解决了我的问题