Shankar M

Shankar M

  • NA
  • 3k
  • 3.3m

window.history.forward(1) + Master Page+Panel + Update Panel

Apr 1 2018 9:40 AM
Hi Team,
 
I have a master Page solution with update panel in WebForm2.aspx which has 2 panel controls. On Page Load I am hiding Panel2 and on click of button in Panel1 I am showing the Panel2. Both these panels are enclosed between Update Panel.
 
With out update panel on the Web Form2.aspx right clicking the page and clicking back does not load the page from cache. But, with update panel control it displays me the First panel which I need to restrict it. Any help appreciated. Thanks
Code
 
Site1.Master
  1. <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication2.Site1" %>  
  2. <!DOCTYPE html>  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5. <title></title>  
  6. <script type="text/javascript">  
  7. window.history.forward(1);  
  8. </script>  
  9. <asp:ContentPlaceHolder ID="head" runat="server">  
  10. </asp:ContentPlaceHolder>  
  11. </head>  
  12. <body>  
  13. <form id="form1" runat="server">  
  14. <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  
  15. <div>  
  16. <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">  
  17. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>  
  18. </asp:ContentPlaceHolder>  
  19. </div>  
  20. </form>  
  21. </body>  
  22. </html>  
WebForm1.aspx
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>  
  2. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
  3. </asp:Content>  
  4. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
  5. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />  
  6. </asp:Content>  
Server code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. namespace WebApplication2  
  8. {  
  9. public partial class WebForm1 : System.Web.UI.Page  
  10. {  
  11. protected void Page_Load(object sender, EventArgs e)  
  12. {  
  13. }  
  14. protected void Button1_Click(object sender, EventArgs e)  
  15. {  
  16. Response.Redirect("WebForm2.aspx");  
  17. }  
  18. }  
  19. }  
WebForm2.aspx
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>  
  2. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
  3. </asp:Content>  
  4. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
  5. <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
  6. <ContentTemplate>  
  7. <asp:Panel runat="server" ID="Panel1" BackColor="#99CCFF" Height="50px">  
  8. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />  
  9. </asp:Panel>  
  10. <br />  
  11. <br />  
  12. <br />  
  13. <br />  
  14. <asp:Panel runat="server" ID="Panel2" BackColor="#FFCC66" ForeColor="Gray" Height="100px">  
  15. <asp:Button ID="Button2" runat="server" Text="Button" />  
  16. </asp:Panel>  
  17. </ContentTemplate>  
  18. </asp:UpdatePanel>  
  19. </asp:Content>  
Server code - Web Form2.aspx
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. namespace WebApplication2  
  8. {  
  9. public partial class WebForm2 : System.Web.UI.Page  
  10. {  
  11. protected void Page_Load(object sender, EventArgs e)  
  12. {  
  13. Panel2.Visible = false;  
  14. }  
  15. protected void Button1_Click(object sender, EventArgs e)  
  16. {  
  17. Panel1.Visible = false;  
  18. Panel2.Visible = true;  
  19. }  
  20. }  
  21. }  
Thanks in Advance.

Answers (1)