早上好, 我有一个非常奇怪的问题。我使用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更改了布局
答案 0 :(得分:1)
对于谁感兴趣我解决了这个问题。 我唯一改变的就是这一行:
string script = @&#34; javascript:window.open(&#39; http://www.microsoft.com&#39;,null,&#39; scrollbars = 1,width = 600,HEIGHT = 400&#39 );&#34 ;; 回复于(script.ToString());
进入这个:
Page.ClientScript.RegisterStartupScript( 的GetType() &#34;的myKey&#34 ;, &#34; window.open(&#39; http://www.microsoft.com&#39;,null,&#39; scrollbars = 1,width = 600,HEIGHT = 400&#39;);&#34;, 真);
我真的不明白为什么会这样,但这样我解决了我的问题。