This is a migrated thread and some comments may be shown as answers.

How can I disable Back-arrow of browser in asp.net c#

2 Answers 413 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jenny
Top achievements
Rank 2
Jenny asked on 06 Dec 2018, 09:53 AM

 Posted 23 hours ago
Hello,
I have homepage with login page. When I am login in it should redirect to homepage but on homepage back arrow of browser should disabled but not forword arrow. 
Below i have attached code which i have tried:

This is my Login page code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Login.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="EmployeePortal.Login" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 
    <style type="text/css">
        .content {
            max-width: 700px;
            margin: auto;
            margin-top: 5px;
            background: #fbfdff;
            color:#000066;
        }
        .auto-style3
        {
            width: 210px;
        }
        .auto-style4
        {
            width: 6px;
        }
        .auto-style5
        {
            width: 10px;
        }
        .btnPass{
            cursor: pointer;
            border-style: none;
            background-color: #fbfdff;
        }
        .txbox{
            border-color:#c5e4ed;
            border-radius:3px;
            border-width:2px;
             
        }
        .auto-style6 {
            width: 6px;
            height: 49px;
        }
        .auto-style7 {
            width: 10px;
            height: 49px;
        }
        .auto-style8 {
            width: 210px;
            height: 49px;
        }
        .auto-style9 {
            height: 20px;
        }
        .auto-style10 {
            width: 6px;
            height: 51px;
        }
        .auto-style11 {
            width: 1px;
            height: 20px;
        }
        .auto-style12 {
            height: 51px;
        }
    </style>
 
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        function preventBack() { window.history.forward(); }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };
    </script>
     <script type="text/javascript">
         window.onload = pageLoad;
         function btnPasswordClick()
         {
             window.radopen("ResetPass.aspx?email=" + document.getElementById('<%=txtEmployeeID.ClientID%>').value.trim(), "Reset Password",580,400,10,10).center;
         }
         function RadWindowClose(sender, args)
         {
             var refresh = args.get_argument();
             if (refresh != true) return false;
         }
         
         function showBrowserEntry()
         {
             var lbl = document.getElementById('<%= txtBrowser.ClientID%>').style.display = 'inherit';
         }
      </script>
     <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" RenderMode="Lightweight" EnableShadow="true" ReloadOnShow="true" ShowContentDuringLoad="false" VisibleStatusbar="false" Modal="true" Behaviors="Close, Move" OnClientClose="RadWindowClose">
    </telerik:RadWindowManager>
                        <table width="100%" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                                <td colspan="2" align="center" style="color:darkblue">
                                    <font face="arial" font-size="x-large" font-weight="300">Welcome to the CPS Portal</font>
                                    <p colspan="2" align="center" style="font-size:smaller;font-weight:200">
                                        <font face="arial" font-size="smaller"> Enter Your Login Information</font>
                                </p>
                                    </td>                             
                            </tr>
                            <tr>
                                <td colspan="4" align="center">
                                    <table width="100%" border="0" cellpadding="10px" cellspacing="5px" >
                                        <tr id="trlblError2" runat="server">
                                            <td colspan="4" align="center">
                                                <asp:Label runat="server" ID="lblErrormessage" SkinID="Error" ForeColor="Red"></asp:Label></td>
                                        </tr>
                                        <tr id="trlblEmployeeID">
                                            <td colspan="4" class="auto-style3">
                                                <asp:Label ID="lblEmail" runat="server" Text="Email Address" Font-Size="smaller" Font-Names="arial"></asp:Label><br />
                                                <asp:TextBox ID="txtEmployeeID" runat="server" Width="350px" Height="20px" CssClass="txbox" align="center" colspan="4"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr id="trlblPassword">
                                            <td colspan="4" class="auto-style8">
                                                <asp:Label ID="lblPassword" runat="server" Text="Password" Font-Size="smaller" Font-Names="arial"></asp:Label><br/>
 
                                                <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" MaxLength="20" CssClass="txbox" Width="350px" Height="20px" align="center" colspan="4"></asp:TextBox><br/>
                                                <div style="margin-top:10px;">
                                                    <asp:Button runat="server" CssClass="btnPass" CausesValidation="false" OnClientClick="btnPasswordClick(); return false;" ID="btnForgotPass" Text="Forgot Password?" Font-Names="arial" Width="350px" ForeColor="#000066" align="center" />
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="4">
                                                <div><asp:RequiredFieldValidator ID="rfEmployeeID" runat="server" ErrorMessage="Enter Email Address"
                                                    ControlToValidate="txtEmployeeID" Display="Dynamic" SetFocusOnError="true" Font-Names="arial" Font-Size="14px" ForeColor="Red"></asp:RequiredFieldValidator></div>
                                                <div><asp:RequiredFieldValidator ID="rfPassword" runat="server" ErrorMessage="Enter Password"
                                                    ControlToValidate="txtPassword" Display="Dynamic" SetFocusOnError="true" Font-Names="arial" Font-Size="14px" ForeColor="Red"></asp:RequiredFieldValidator></div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left" style="width:2px; padding:0px;" colspan="1" class="auto-style11" oncontextmenu="showBrowserEntry()">
                                                <asp:TextBox ID="txtBrowser" runat="server" Style="display: none;" Text="N/A"></asp:TextBox> </td>                                              
                                            <td class="auto-style12" align="center" colspan="4">
                                                <asp:ImageButton ID="btnLogin" runat="server" ImageUrl="~/Images/Login2.gif" Color="#000066" OnClick="btnLogin_Click" />
                                            </td>
                                        </tr>
                                    </table>
                                    <div align="center">
                                    <asp:Panel ID="pnlLogin1" runat="server">
 
                                    </asp:Panel>
                                    </div>
                                </td>
                            </tr>
                        </table>
        <asp:HiddenField runat="server" ID="hdfBrowser" />
</asp:Content>

 

This is my home page:

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="EmployeePortal.HomePage" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function RadWindow1_ClientClose(sender, args) {
            //$find("RadToolBar1").findItemByValue("Delete").click();
            __doPostBack('pdfStamper', 'PdfSave');
        }
        function CloseRadWindow() {
            //get a reference to the current RadWindow
            var wndow = GetRadWindow();
            wndow.Close();
        }
        function OnClientResizeEnd(sender, eventArgs) {
            logEvent("<strong>OnClientResizeEnd</strong>: RadWindow is resize ended");
        }
        function UseRadWindow() {
            var oManager = GetRadWindowManager();
            var oWnd = oManager.getWindowByName("DialogWindow");
            oWnd.show();
            oWnd.setSize(400, 400);
            oWnd.minimize();
            oWnd.maximize();
            oWnd.restore();
        }
        function OnClientResizeStart(sender, eventArgs) {
            logEvent("<strong>OnClientResizeEnd</strong>: RadWindow is resize started");
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
        function showReport(pdfPath) {
            var mywindow;
            //  pdfPath = "../HR/Forms/PDF_Files/DEMOCO/152-02-2018_W-4.pdf";
            mywindow = window.radopen(pdfPath, "RadWindowPDF");
 
        }
        function OnClientValidationFailed(sender, args) {
            var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
            if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
                if (sender.get_allowedFileExtensions().indexOf(fileExtention)) {
                    alert("Only PDF files are allowed.");
                }
                else {
                    alert("Wrong file size!");
                }
            }
            else {
                alert("not correct extension!");
            }
        }
        function promptCallBackFn(arg) {
            $get("<%= hdfPrompt.ClientID %>").value = arg;
            __doPostBack();
        }
    </script>
 
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" VisibleOnPageLoad="True" AutoSizeBehaviors="Width"
        Height="768px" Width="1024px" Skin="Office2007" Behaviors="Default" KeepInScreenBounds="True" Style="z-index: 12345"
        Modal="false" VisibleStatusbar="false" ShowContentDuringLoad="true" DestroyOnClose="true">
        <Windows>
            <telerik:RadWindow Title="RadGrid PDF Output" runat="server" ID="RadWindowPDF" Skin="Office2007" KeepInScreenBounds="true" Style="overflow-x: hidden; overflow-y: hidden; z-index: 1000"
                ReloadOnShow="true" VisibleOnPageLoad="false" Behaviors="Close,Maximize,move" OnClientClose="RadWindow1_ClientClose"
                Width="700px" Height="800px" MaxWidth="1000px" MaxHeight="900px">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    <asp:HiddenField runat="server" ID="hdfPrompt" Value="" />
    <style type="text/css">
        .label {
            border-color: #000066;
            color: darkblue;
            font-family: Arial, Helvetica, sans-serif;
            margin-top: 7px;
            padding: 5px;
        }
 
        .td {
            border-color: #000066;
        }
 
        .RadButton.rbButton.rbPrimary {
            padding-left: 3.5em !important;
        }
 
        .img-circle {
            width: 50px;
            height: 50px;
        }
    </style>
 
 
 
 
    <table style="width: 99%; height: 340px;">
        <tr>
             
            <td style="vertical-align: top; width:10%; height:10%">
                <div style="float: initial" id="imgpic">
                    <telerik:RadBinaryImage ID="RBILogo" runat="server" Width="35px" />
                </div>
            </td>
 
            <td rowspan="2" style="border-style: none; border-color: inherit; border-width: medium; width: 35%; padding-left: 2px" class="td">
                <asp:TextBox ID="txtmsg" ReadOnly="true" Font-Size="Medium" ForeColor="darkblue" Style="resize: none" BackColor="#ebf0ff" SkinID="bootstrap" BorderStyle="solid" BorderColor="#c5c7c5" TextMode="MultiLine" Width="97%" Height="300px" runat="server" CssClass="label" EnableTheming="False"></asp:TextBox>
            </td>
            <td rowspan="2" style="border-style: none; width: 35%; margin-top: 2px; padding-right: 20px; color: darkblue">
                <telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnLoad="RadDockLayout1_Load" Skin="Windows7">
                    <telerik:RadDockZone ID="RadDockZone1" runat="server" Height="300px" Width="100%" MinHeight="100px" Style="float: left; margin-top: 2px; margin-left: 8px; margin-right: 0px;" RenderMode="Lightweight" Skin="Windows7" ForeColor="DarkBlue">
                    </telerik:RadDockZone>
                </telerik:RadDockLayout>
            </td>
        </tr>
    </table>
    <table style="width: 98%; height: 150px; margin-left: 5px;">
        <tr>
            <td style="width: 30%;">
                <telerik:RadButton RenderMode="Lightweight" runat="server" ID="rbtnMyProfile" Height="80px" Width="200px" Text="My Profile" OnClick="RadMyProfile_Click" Skin="Bootstrap" ForeColor="#ffffff" BackColor="#15D67F" Font-Size="20px">
                    <Icon PrimaryIconUrl="images/profile.png" PrimaryIconTop="16px" PrimaryIconLeft="20px" PrimaryIconWidth="50px" PrimaryIconHeight="50px"></Icon>
                </telerik:RadButton>
            </td>
            <td style="width: 30%;">
                <telerik:RadButton RenderMode="Lightweight" runat="server" ID="rbtnMyDD" Height="80px" Width="200px" Text="Direct Deposit" OnClick="RadMyDD_Click" Skin="Bootstrap" ForeColor="#ffffff" BackColor="#0876b4" Font-Size="20px">
                    <Icon PrimaryIconUrl="images/deposit.png" PrimaryIconTop="16px" PrimaryIconLeft="20px" PrimaryIconWidth="50px" PrimaryIconHeight="50px"></Icon>
                </telerik:RadButton>
            </td>
            <td style="width: 30%;">
                <telerik:RadButton RenderMode="Lightweight" runat="server" ID="rbtnMyDeds" Height="80px" Width="200px" Text="Deductions" OnClick="RadMyDeds_Click" Skin="Bootstrap" ForeColor="#ffffff" BackColor="#15D67F" Font-Size="20px">
                    <Icon PrimaryIconUrl="images/deductions.png" PrimaryIconTop="16px" PrimaryIconLeft="20px" PrimaryIconWidth="50px" PrimaryIconHeight="50px"></Icon>
                </telerik:RadButton>
            </td>
            <td style="width: 30%;">
                <telerik:RadButton RenderMode="Lightweight" runat="server" ID="rbtnForms" Height="80px" Width="200px" Text="Forms & Documents" OnClick="RadForms_Click" Skin="Bootstrap" ForeColor="#ffffff" BackColor="#0876b4" Font-Size="20px">
                    <Icon PrimaryIconUrl="images/filesdocs.png" PrimaryIconTop="16px" PrimaryIconLeft="20px" PrimaryIconWidth="50px" PrimaryIconHeight="50px"></Icon>
                </telerik:RadButton>
            </td>
 
        </tr>
    </table>
    <table>
        <tr>
            <td style="width: 80%; border: solid 1px; border-color: #c5c7c5; padding: 5px; padding-bottom: 20px">
 
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" Height="100%" BorderColor="#000066">
                    <asp:Label ID="lblRecentPay" Style="text-align: right;" runat="server" Text="My Recent Pay Check:" CssClass="label" ForeColor="darkblue" Font-Names="arial">
                    </asp:Label>
 
                    <asp:DropDownList ID="ddlChecks" runat="server" Width="200px" AutoPostBack="true" OnSelectedIndexChanged="ddlChecks_SelectedIndexChanged" CssClass="RadDropDownList_CustomDD">
                    </asp:DropDownList>
                    <br />
                    <br />
 
                    <telerik:RadGrid ID="RadgridRecentPay" runat="server" EnableEmbeddedSkins="False" Skin="Custom1" Width="100%" Height="105px" Font-Names="Arial" Font-Size="Small" RenderMode="Lightweight">
                        <ClientSettings>
                            <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                        </ClientSettings>
                        <GroupingSettings CollapseAllTooltip="Collapse all groups" />
                        <MasterTableView AutoGenerateColumns="false" ForeColor="DarkBlue" Font-Size="Smaller">
                            <Columns>
                                <telerik:GridBoundColumn DataField="GROSSPAY" HeaderText="Gross Pay">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="NETAMT" HeaderText="Net Amount">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="REGHRS" HeaderText="Regular Hours">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="OVTHRS" HeaderText="Over Hours">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DBLHRS" HeaderText="Double Hours">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="VACHRS" HeaderText="Vacation Hours">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="SICKHRS" HeaderText="Sick Hours">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="TIPSREPORTED" HeaderText="Tips Reported">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="OtherPayAvg" HeaderText="Other Pay">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="deductionAvg" HeaderText="Deductions">
                                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="TotalTax" HeaderText="Total Tax">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn CancelImageUrl="Cancel.gif" InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                        <HeaderStyle Font-Bold="True" />
                        <FilterMenu EnableEmbeddedSkins="False">
                        </FilterMenu>
                        <HeaderContextMenu EnableEmbeddedSkins="False">
                        </HeaderContextMenu>
                    </telerik:RadGrid>
                </telerik:RadAjaxPanel>
                <table>
                    <tr>
                        <td align="right">
                            <asp:Label ID="lblVac" Style="text-align: right;" runat="server" ForeColor="darkblue" Font-Names="arial" CssClass="label">
                            </asp:Label>
                            <asp:Label ID="lblVacBal" Style="text-align: left;" runat="server" ForeColor="darkblue" Font-Names="arial" CssClass="label">
                            </asp:Label><br />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="lblPto" Style="text-align: right;" runat="server" ForeColor="darkblue" Font-Names="arial" CssClass="label">
                            </asp:Label>
                            <asp:Label ID="lblPtoBalance" Style="text-align: left;" runat="server" ForeColor="darkblue" Font-Names="arial" CssClass="label">
                            </asp:Label>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
      
        </tr>
    </table>
</asp:Content>

 

Previously i tried this javascript on home page  it was working for disabling back arrow bt it is clearing forword arrow's history also. Below i have attached code:

history.pushState(null, null, location.href);
    window.onpopstate = function () {
        history.go(1);
    };

 

Please help me out as soon as possible..

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 06 Dec 2018, 11:56 AM
Hello Jenny,

Due to security and many other reasons, there is no direct and easy way to manipulate the browser button. Nevertheless, you can check the possible approaches that achieve a similar functionality in one of the following forum posts:
Regards,
Peter Milchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jenny
Top achievements
Rank 2
answered on 06 Dec 2018, 01:11 PM

these all i have tried but not getting result. 

Can't i write any code to destroy history of back button not for previous.

Please you have any solution then tell me..

Tags
Window
Asked by
Jenny
Top achievements
Rank 2
Answers by
Peter Milchev
Telerik team
Jenny
Top achievements
Rank 2
Share this question
or