您的位置:首页 > 编程语言 > ASP

asp.net 下 使用 showModalDialog 模式窗口 (记录)

2010-04-21 12:45 537 查看
经历些许破折... 终于搞出来 模式窗体了... 留作纪念...

① 页面放置 GirdView 控件 用来展示信息列表

页面截图: (操作列中的 "回复" 是个 超链接..点击之后打开模式窗口.并且传值过去)

页面源代码

<asp:GridView ID="gvnotReturn" runat="server" AutoGenerateColumns="False" AllowPaging="True"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical" OnPageIndexChanging="gvnotReturn_PageIndexChanging1"
PageSize="5" Width="100%">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="cbno" runat="server" />
</ItemTemplate>
<ItemStyle Width="30px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Eval("gid") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="40px" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("gTitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="留言日期">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("gPubDate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="120px" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<a href="javascript:showModalDialog('ansmsg.aspx?id=<%#Eval("gid")%>');window.location.reload()">
回复</a>
</ItemTemplate>
<ItemStyle Width="50px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>


源代码解释:

<a href="javascript:showModalDialog('ansmsg.aspx?id=<%#Eval("gid")%>');window.location.reload()">
回复</a>


很普通的一个页面指向链接.. 传参数ID 过去... 后便添加了 window.location.reload()

这个 window.location.reload() 的意思是 .. 模式窗体关闭之后刷新父页面

ansmsg.aspx 就是要弹出来的 模式窗体咯..

在 ansmsg.aspx 页面添加如下代码:

protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = 0;    }


这个意思是 禁止 模式窗体页面缓存..

如果不这样做的话... 地址栏ID不变.. 内容也不会变..

就比如..我的功能是这样的.. 如图:



这样的情况下..如果不添加禁止页面缓存..我需要回复 留言版信息.. 重新从 "回复" 链接打开的模式窗体..内容是不会变的.. 即使数据库中已经更新了...

如果这个页面紧紧是展示信息..而没有提交按钮...我想这样做已经OK 了...

但是我这个模式窗体有个 提交按钮..意思就是说我需要回发数据回去..

这个时候就出现一个问题....

当点击了 提交按钮之后... 这个模式窗体 会在新页面打开...

失去了模式窗体的意义...

这个不太好...但是怎么解决呢?

方法很简单..

在 作为模式窗体弹出的 那个页面 页面源代码中添加如下代码..

</head>
<base target="_self" />
<body>


到这里...一切OK /./.大功告成.... 感谢各位看客...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: