页面刷新的各种问题
页面刷新之后出现的几个问题:
1. 按F5按钮会弹出“不重新发送信息,则无法显示网页”的提示框;
2. 前台页面有两个按钮,一个是点击后会将查询数据库数据显示在gridview;一个是点击后会将查询数据显示在文本框。按F5刷新后,这两个控件显示内容都不会重置,仍然显示查询后数据;
3. 如果点击了gridview的第二页,此时按F5刷新仍然会显示第二页。。
崩溃中。。
后台代码:
public partial class freightList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["searchSql"] = null;
}
bindFreight();
}
protected void bindFreight()
{
string sql = "select * from cargo";
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
}
protected void gvFreight_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string sql;
sql = Convert.ToString(Session["searchSql"]);
if (Session["searchSql"] == null)
{
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
else
{
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string table ="cargo";
string keyType1 = "ID";
string keyType2 = "terminal";
string keyType3 = "date";
string keyType4 = "trainNumber";
string key1 = orderID.Text;
string key2 = terminal.Text;
string key3 = leaveDate.Text;
string key4 = trainNumber.Text;
string sql;
if (key1 != "" || key2 != "" || key3 != "" || key4 != "")
{
sql = "select * from " + table + " where " + keyType1 + " like '%" + key1 + "%' and " + keyType2 + " like '%" + key2 + "%' and " + keyType3 + " like '%" + key3 + "%' and " + keyType4 + " like '%" + key4 + "%'";//
Session["searchSql"] = sql;
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
//Session["searchType"] = ddlSearchType.SelectedValue.ToString();
}
else
{
sql="";
RegisterStartupScript("false", "<script>alert('请输入查询条件!')</script>");
}
}
protected void Button4_Click(object sender, EventArgs e)
{
string surplus = " ";
string sql;
sql = "select ID from box where isEmpty <> 0";
DataSet ds = dataOperate.getDataset(sql, "box");
int i = 0;
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
surplus = surplus + "\r" + ds.Tables[0].Rows[i][0].ToString();
}
surplusBox.Text = surplus;
}
}
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="freightList.aspx.cs" Inherits="freightList" Title="货源信息" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table valign="center" align="center" height="435" cellpadding="0" cellspacing="0" style="width: 960px">
<tr valign="top" align="center" bgcolor="#FFFFFF" style="height: 315px">
<td>
<%--<td align="right" style="width: 569px">--%>
<asp:GridView ID="gvFreight" runat="server" AutoGenerateColumns="False" Width="960px" AllowPaging="True"
OnPageIndexChanging="gvFreight_PageIndexChanging" CssClass="huise1"
CellPadding="4" ForeColor="Black" GridLines="Vertical"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="订单编号" />
<asp:BoundField DataField="trainNumber" HeaderText="车次" />
<asp:BoundField DataField="consignor" HeaderText="发货人" />
<asp:BoundField DataField="consignee" HeaderText="发收货人" />
<asp:BoundField DataField="start" HeaderText="出发地" />
<asp:BoundField DataField="terminal" HeaderText="到达地" />
<asp:BoundField DataField="price" HeaderText="货物运价" />
<asp:TemplateField HeaderText="重量(g)">
<ItemTemplate>
<%#Eval("weight") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="date" DataFormatString="{0:yyyy-MM-dd}" HeaderText="发布日期"
HtmlEncode="False" />
<asp:TemplateField HeaderText="详细信息">
<ItemTemplate>
<a href="#" onclick='openPWD("freightInfo.aspx?ID=<%#Eval("ID")%>",507,500)'>详细信息</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<%-- <%#Eval("weight") %>--%>
</table>
<script language='javascript'>
function openPWD(i,width,height)
{
window.showModalDialog(i,"","dialogHeight: "+height+"px; dialogWidth: "+width+"px;dialogTop:px; dialogLeft:px; edge: Raised; center: Yes; help: No; resizable: No; status: No;scroll:No");
}
</script>
</asp:Content>
你可以用一个html页面,上面放一个 表单,弄个提交按钮,你试一试。
但是如何防止别人按F5呢
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script>
window.onkeydown = function(e)
{
if(event.keyCode==116 )
{
alert("do not F5")
event.returnValue = false;
event.preventDefault();
}
}
</script>
</BODY>
</HTML>