Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

back button postback

Status
Not open for further replies.

javs1983

Programmer
Apr 17, 2008
2
'm working on a huge code base, so have made a small sample to simulate the issue that I am currently facing.

This is my aspx file:-



<%@ PageLanguage="C#"AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""


<html xmlns="
<head runat="server">

<title>UntitledPage</title>

</head>

<body>

<form id="form1" runat="server">

<input type ="hidden" name="inp_hid" value = "popupIsClosed"/>

<div>

<br />

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">POPUP</asp:LinkButton><br />

<br />

<br />

<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">TEXTBOX</asp:LinkButton><br />

<br />

<br />

<asp:TextBox ID="TextBox1" Visible="false" runat="server"></asp:TextBox>&nbsp;</div>

</form>

</body>

</html>



And, this is my code-behind:



using System;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;



public partial class _Default : System.Web.UI.Page

{



protected void Page_Load(objectsender, EventArgs e)

{







}

protected void LinkButton1_Click(objectsender, EventArgs e)

{



stringstrScript = "<scriptlanguage=javascript>window.open('
Page.ClientScript.RegisterStartupScript(typeof(string),"Start",strScript);







}

protected void LinkButton2_Click(objectsender, EventArgs e)

{

TextBox1.Visible = true;

}







}



Steps to simulate :-



1. Click on the link button that has the text "POPUP",the popup shows
2. next click on the link button that has the text "TEXTBOX",the textbox becomes visible.
3. Click on the back button and the pop-up shows again.





Issue:-

In my actual code I am working on a nested master page architecture,so I can't use "Resposnse.Write" to write the javascript as that disturbs the alignment of my page.

So, what I was doing was trying to disable the server side and the client side cache so that the page can be executed fresh.

I did that and the cache is deleted.

But now the issue is that when I click on the back button,it says that the page has expired and asks me to refresh the page when I do so,the back button does a postback and the popup comes again.

This is what I tried, it works the first time but fails the second time.Please help:-(



using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



public partial class _Default : System.Web.UI.Page

{



protected void Page_Load(object sender, EventArgs e)

{



Response.Cache.SetCacheability(HttpCacheability.NoCache);

if (!this.IsPostBack)

{

Session["update"] = "xxxx";

}











}

protected void LinkButton1_Click(object sender, EventArgs e)

{



if (Session["update"].ToString() == ViewState["update"].ToString())

{

string strScript = "<script>window.open('
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "Start", strScript);



}



Session["update"] = " ";





}

protected void LinkButton2_Click(object sender, EventArgs e)

{

TextBox1.Visible = true;

}

protected void Page_PreRender(object sender, EventArgs e)

{





ViewState["update"] = Session["update"];



}









}
Please help.
Thanks
 
if all you're doing is executing a popup window and showing/hiding a text box you are better off use js/dom/css rather than make multiple round trips to the server.

checkout forum215 and forum216 for more info

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hey,

Thanks for the reply Jason. I know what you’re saying is true.
But actually in my actual code base, on the click of a link button, I first need to do some server side validations and then only I want the popup to appear.
So, I use this code for the javascript pop-up in my code behind.:

string strScript = "<script>window.open('
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "Start", strScript);

Now the problem was that on running the site when this popup used to come, if I clicked anywhere else and then click the back button, the popup used to come up again ?

This is my orginal issue, so for resolving this I disabled the cache but the issue was that when I disabled the cache and the user clicked on back button, he would not find the page, but when he would click the refresh button, the pop-up would come up again.

This is my issue.
Would appreciate your help.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top