2015-10-10 104 views
1

這是aspx設置。當我修改DropDownList時,一個項目被添加到我的瀏覽器的歷史記錄中,這會導致不必要的「返回」點擊來轉義頁面。如何防止代碼修改瀏覽器歷史記錄?

如何防止aspx修改瀏覽器的歷史記錄?

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="RealTimeTracking.aspx.cs" Inherits="RealTimeTracking" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
    <title>Real Time Tracking</title> 
    <script type="text/javascript"> 
     function UpOneLevel() { 
      window.location.href = "TableofContents.aspx"; 
     } 
    </script> 

    <link href="Calender/Style/calendar-blue.css" rel="stylesheet" type="text/css" /> 
    <script language="javascript" src="Calender/calendar.js" type="text/javascript"></script> 

    <script language="javascript" src="Calender/calendar-setup.js" type="text/javascript"></script> 

    <script type="text/javascript" src="Calender/lang/calendar-en.js"></script> 
</asp:Content> 
<asp:Content ID="masterBody" ContentPlaceHolderID="body" runat="server"> 
    <h2 class="text"> 
     Real Time Tracking</h2> 
    <h3 class="text"> 
     Select a Unit</h3> 
    <h5 class="userinfotable"> 
     Phone: 
     <asp:Label ID="lbl_PhoneValue" runat="server"></asp:Label></h5> 
    <h5 class="userinfotable"> 
     Client: 
     <asp:Label ID="lbl_ClientValue" runat="server"></asp:Label></h5> 
    <asp:Label ID="lblErrormsg" runat="server" CssClass="words"></asp:Label> 
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;"> 
     <tr> 
      <td> 
       <asp:Label ID="txtPleaseSelect" runat="server" CssClass="words" Style="padding: 0px;"> 
        Please Select an Asset from the drop down menu.</asp:Label> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:Label ID="lblMsg" runat="server" CssClass="vedispMsg"></asp:Label> 
       <asp:DropDownList ID="DropSelectUnit" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropSelect_SelectedIndex" 
        OnLoad ="DropSelect_SelectedIndex" 
        DataTextField="Text" 
        DataValueField="Value" 
        CssClass="tdsubmitbutton" Width="100%"> 
       </asp:DropDownList> 
      </td> 
     </tr> 
    </table> 
    <asp:Button ID="GoButton" runat="server" Text="Go To Map" OnClick="GoButton_Click" CssClass="tdsubmitbutton" Width="130px" /> 
    <p> 
     &nbsp; 
    </p> 
    <p> 
     &nbsp; 
    </p> 
    <asp:PlaceHolder runat="server" OnLoad="PingRateTable"> 
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;padding-bottom:2px;"> 
     <tr> 
      <td> 
       <asp:Label ID="Label1" runat="server" CssClass="words" Style="padding: 0px;"> 
        Select a Ping Rate.</asp:Label> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:Label ID="Label2" runat="server" CssClass="vedispMsg"></asp:Label> 
       <asp:DropDownList ID="PingRate" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PingRate_SelectedIndex" 
        OnLoad ="PingRate_SelectedIndex" 
        CssClass="tdsubmitbutton" Width="100%"> 
       </asp:DropDownList> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       &nbsp; 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:Button ID="PingButton" runat="server" Text="Set Ping Rate" OnClick="PingButton_Click" CssClass="tdsubmitbutton" Width="130px" /> 
      </td> 
     </tr> 
    </table> 
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;padding-top:0px;"> 
     <tr> 
      <td> 
       <asp:Label ID="IsPingSet" runat="server" CssClass="words" Style="padding: 0px;"></asp:Label> 
      </td> 
     </tr> 
    </table> 
    </asp:PlaceHolder> 
    <div style="visibility:hidden;"> 
     <input type="text" id="formlatitude" name="latitude" /> 
     <input type="text" id="formlongitude" name="longitude" /> 
     <input type="text" id="formassetname" name="asset" /> 
     <input type="text" id="formdatetime" name="dateandtime" /> 
     <input type="text" id="formaddress" name="address" /> 
    </div> 
</asp:Content> 

代碼隱藏C#

protected void Page_Load(object sender, EventArgs e) 
{ 
    Common.CheckAnyLogin(); 
    Session["Action"] = Request.Url; 
    AssetHelper assethelp = new AssetHelper(); 
    IsPingSet.Text = ""; 
    if (!IsPostBack) 
    { 
    } 
} 


protected void DropSelect_SelectedIndex(object sender, EventArgs e) 
{ 
    if (sender.GetType().Name == "DropDownList") 
    { 
     Session["UnitName"] = ((DropDownList)sender).SelectedItem; 
     Session["SerialNo"] = ((DropDownList)sender).SelectedValue; 
    } 
} 

Master.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<!--This master page encompasses all pages that require the user to be logged in. 
This means that WhatIsThis.aspx, Logoff.aspx, Default.aspx, 
SearchForAsset-Map.aspx, MyLocation-Map.aspx, 
FleetTracking-Map.aspx, and AssetHistory-Map.aspx are not included in this masterpage.--> 

<head runat="server"> 
<!--Apple iPhone and iPad compatibility--> 
    <meta name="apple-mobile-web-app-capable" content="yes" /> 
    <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
    <link rel="apple-touch-startup-image" href="images/splashscreen.png" /> 
    <link rel="apple-touch-icon" href="images/Sights57.png" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> 
    <meta name="format-detection" content="telephone=no" /> 
<!--Microsoft Bing Maps--> 
    <script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script> 
    <script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script> 
    <script type="text/javascript" src="/js/jquery-bing-maps/jquery.ui.bmap.js"></script> 
<!--CSS and Javascript--> 
    <link rel="stylesheet" href="css/login.css" /> 
    <link rel="stylesheet" href="css/navbuttons.css" /> 
    <script type="text/javascript" src="js/topofpage.js"></script> 
    <asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder> 
</head> 
<body style="min-height:391px;" runat="server" id="masterbody"> 
<form id="wholepageform" runat="server"> 
<div id="topofpage"> 
<!--#include virtual="header.html"--> 
<div style="height:43px;"><br /></div> 
<div class="undersightslogo" id="undersightslogo"> 
    <asp:ContentPlaceHolder id="body" runat="server"></asp:ContentPlaceHolder> 
    <div id="copyright"><h6> 
    &copy; Reltronics Technologies <script type="text/javascript">document.write(new Date().getFullYear());</script> 
    </h6></div> 
</div> 
</div> 
</form> 
</body> 
</html> 

header.html中只是一個包含我的頭,包括我UpOneLevel按鈕

謝謝。

+1

如果您正在從下拉菜單中進行回覆,則無法進行此操作。如果你把它改成了ajax,它應該可以工作。 – Seabizkit

+0

我該怎麼做?我確實有jquery –

+1

谷歌和研究...新問題.... – Seabizkit

回答

0

設置AutoPostBack="false"應該可以解決您的問題。

+0

這樣做會導致服務器端代碼停止執行。雖然它會「解決」所問的問題,但它會破壞OP發佈代碼的其他部分。 –

+0

@ SamAxe是真實的,但它是問題的確切答案。您假設OP將無法找到一種通過使用Ajax請求來完成剩餘工作的替代方法。我發現大部分時間(在生活中可能不是這樣),人們只需要幫助找出導致問題的代碼,而不希望爲他們編寫完整的解決方案。 – Frenchie