showModalDialog打开的窗口关闭时会运行父窗口的load事件,也就是自动刷新的。前段时间碰到个问题,要求关闭时不允许刷新父窗口,试了很多方法,总算找到个只适用我那个页面的方法。不是用js代码,因为都是asp.net服务器端代码,js不太好实现。今天遇到个新问题,父窗口里有个gridview,使用SqlDataSource控件绑定数据。页面上还有一个按钮,点击后用showModalDialog打开窗口,在showModalDialog页面中删除了数据源的一条记录,关闭子窗口,但问题是,父窗口的gridview怎么也不刷新。测试了关闭showModalDialog窗口确实运行了父窗口的load事件,在load里手动写上gridview的databind()方法也无效。请教了!
解决方案 »
- 大家帮帮忙!教教我如何将HeaderText赋值动态?
- WCF,LINQ,Entity,MVC的人请加入群 88718955
- 难道学ASP.Net就是学拖控件吗
- 如何查找html代码里第一个图片<img ...并提取出来
- 紧急
- 急,请教一个编码的问题..
- 多次使用SqlDataReader的问题。
- 菜鸟问题:datagrid问题
- 急问急问,关于建立一个DATASET,马上给100分!
- Crystal Reports 9 Chs里只有三个文件 CR9CHS.CCD\CR9CHS.IMG\CR9CHS.SUB请问如何去安装呢?
- asp.net 怎样加密最后生成的dll文件!并且可以不影响程序的正常远行?
- 如何把Excel表不同工作薄的数据导入Sql
if(!IsPostBack)
{}
http://dotnet.aspx.cc/article/49ml4ao8-5pb3-4kny-njzd-ljoioxv4m1x4/read.aspx
http://blog.csdn.net/net_lover/archive/2002/09/24/6910.aspx
我看了那两篇贴子。以前也看过。不过我觉得我的问题跟那里面的内容没有什么关系。
我现在是在子窗口中改变了数据库的内容,关闭子窗口后,回到父窗口,父窗口中其他的控件内容都按照自己的load事件里的程序重新初始化了,但gridview没有改变,而查看数据库,确实已经改变了,也就是说,gridview没有刷新,怎样使他刷新,我觉得和showModalDialog的关系不是非常大。
烦孟老大再看看。
父页面
function OpenNewDialogBox()
{
var varURL = DialogBox.aspx?DialogURL=子页面.aspx"
var varOptions = "dialogWidth:"+dialogWidth+"px;dialogHeight:"+dialogHeight+"px;status:no;resizable: Yes;scroll:Yes;help:NO";
var array = new Array(); array[0] = "";
array[1] = window;
var rtvalue = window.showModalDialog(varURL,array,varOptions);
if(rtvalue==true )
{
document.getElementById("btn_hide").click();
}
}
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<IFRAME src="<%=Request.QueryString["DialogURL"].ToString().Replace("@", "&")%>" id="frmdialogcontent" scrolling="Yes" name="frmdialogcontent" style="Z-INDEX: 1; VISIBILITY: visible; WIDTH: 100%; HEIGHT: 100%; BACKGROUND-COLOR: #ffdabe" frameBorder="0">
</IFRAME>
</form>
</body>
子页面关闭时候
Page.RegisterStartupScript("Close","<script language='javascript'>window.close();window.returnValue=true;</script");
里面的 btn_hide 里面写 你的gridview绑定事件不就可以刷新 ?
btn_hide是一个服务器端的Button啊!
你上面的父页面的代码是客户端的js代码吧? 我的这个gridview中每行都有个按钮用来打开子窗口,对按钮所在行进行编辑,按钮的事件中有获取本行关键字的服务器端程序。所以不太好把打开子窗口的程序完全写成js代码放在客户端。我在服务器端写的:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As String = "window.showModalDialog('2.aspx?AdType1ID=" + sender.parent.parent.cells(0).text+ "','','dialogWidth:300px;dialogHeight:300px;dialogLeft:400px;dialogTop:300px;status:0;scroll:no;menubar:no;help:no;');"
Response.Write("<script language='javascript'>" & url & "</script>")
End Subsender.parent.parent.cells(0).text是获取本行关键字段的值再帮我看看
1.aspx(父窗口,一个SqlDataSource连接数据源,一个GridView,显示数据,每行有个linkbutton,点击后打开子窗口2.aspx):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="1.aspx.vb" Inherits="Approve_1" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStr %>"
SelectCommand="SELECT * FROM [AdType1]">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView_Approve" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="AdType1ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="AdType1ID" HeaderText="AdType1ID" InsertVisible="False"
ReadOnly="True" SortExpression="AdType1ID" />
<asp:BoundField DataField="AdType1Name" HeaderText="AdType1Name" SortExpression="AdType1Name" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">编辑</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
Imports System.Collections
Imports System.Data
Imports System.Data.sqlclient
Partial Class Approve_1
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As String = "window.showModalDialog('2.aspx?AdType1ID=" + sender.parent.parent.cells(0).text + "','','dialogWidth:300px;dialogHeight:300px;dialogLeft:400px;dialogTop:300px;status:0;scroll:no;menubar:no;help:no;');"
Response.Write("<script language='javascript'>" & url & "</script>")
End Sub
End Class
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStr %>"
SelectCommand="SELECT * FROM [AdType1]">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView_Approve" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="AdType1ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="AdType1ID" HeaderText="AdType1ID" InsertVisible="False"
ReadOnly="True" SortExpression="AdType1ID" />
<asp:BoundField DataField="AdType1Name" HeaderText="AdType1Name" SortExpression="AdType1Name" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" OnClientClick="window.showModalDialog('2.aspx?AdType1ID=" + <%# Eval("AdType1ID")%>+ "','','dialogWidth:300px;dialogHeight:300px;dialogLeft:400px;dialogTop:300px;status:0;scroll:no;menubar:no;help:no;');">编辑</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>后台
Imports System.Collections
Imports System.Data
Imports System.Data.sqlclient
Partial Class Approve_1
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
这里写重新绑定GirdView...
End Sub
End Class
2.aspx(子窗口,一个文本框,一个按钮)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="2.aspx.vb" Inherits="Approve_2" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
<base target="_self"/>
<meta http-equiv="pragma" content="no-cache"/>
</head>
<body>2.aspx.vb:
Imports System.Web
Imports System.Collections
Imports System.Data
Imports System.Data.sqlclient
Imports AdCensor.BusinessLogic
Imports AdCensor.DataAccess
Partial Class Approve_2
Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DA_Approve.DA_UpdateAdType1(Request.QueryString("AdType1ID"), TextBox1.Text)
Response.Write("<script language='javascript'>self.close()</script>")
End Sub
End Class
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>DA_Approve.DA_UpdateAdType1()是调用数据层的函数操作数据库
试过没用,按钮按下去,不管服务器段还是客户端的程序都一起运行的啊,没法控制子窗口关闭了后再让gridview重新绑定。很奇怪的问题,在page_load事件中写databind()都没用。
1.aspx里只管弹出2.aspx,然后在弹出的2.aspx关闭后重新绑定要GridView就好.按我先前发的代码应该可以实现的,不知你有没有拿去测试..
空谈是没用的 - 用事实说话[引用广告词] :)
搞了半天,最后在gridview的RowDataBound事件中指定刚生成的行中LinkButton1的OnClientClick的代码,此时可以获取刚生成的行中AdType1ID的值。
真的很搞人的问题。
OnClientClick='<%# "window.showModalDialog(\"2.aspx?AdType1ID=" + Eval("AdType1ID") + "\");"%>'