Page_Load event not fired

A

Alfons Puig

Some pages (not all the pages, but I can't observe differences) opened from
javascript via window.showModalDialog() doesn't fire the codebehind
Page_Load event the second (and further) time it is opened from the same
window.

If I change the IE configuration of the temporary internet files to check
new versions every time the page is called then the event is fired. However
it is not an acceptable solution.

Thanks.

Alfons Puig
(e-mail address removed)
 
I

Igor Tandetnik

Alfons Puig said:
Some pages (not all the pages, but I can't observe differences) opened from
javascript via window.showModalDialog() doesn't fire the codebehind
Page_Load event the second (and further) time it is opened from the same
window.

If I change the IE configuration of the temporary internet files to check
new versions every time the page is called then the event is fired. However
it is not an acceptable solution.

From your server, send appropriate HTTP cache control headers, such as
Exprires: or Pragma: no-cache, to prevent the page from being cached.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
 
S

Steven Cheng[MSFT]

Hi Alfons,


Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, when you loaded a page again(second time) using
"window.showModalDialog" javascript code, the page(be opened) seemed not be
newly loaded(page's server Load event was not fired)
However, when you change the IE's page "check for new version always" as
true, it worked, yes?
If there is anything I misunderstood, please feel free to let me know.


I've done some tests on my side and did encountered the same problem. I've
also tried Steve's suggestion that set the page's client cache attribute
via:
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");

Yes, this did work. So the problem is due to the client cache. The page
popuped be the "showModalDialog" may be cached by default. You may also try
Steve's solution to see whether it works for you.
In addition, here is the test page I used to test Steve' suggestion, you
may have a look as reference if you have anything unclear:

------------------------------first page's aspx
file--------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PopUp</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
var hNew

function PopUp()
{
var dt = new Date();
divMessage.innerText = dt.getMilliseconds();

hNew = window.showModalDialog("Refresh.aspx");
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><div id="divMessage"></div>
</td>
</tr>
<tr>
<td><INPUT id="btnShow" type="button" value="ShowPage"
onclick="PopUp()"></td>
</tr>
</table>
</form>
</body>
</HTML>

---------------------------the poped up page's aspx page
file-------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Refresh</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<base target=_self>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label>
</td>
<td>
<asp:Button ID="btnPost" Text="Post Back" Runat="server"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</HTML>
------------------------------the poped up page's code behind page
class----------------------
public class Refresh : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnPost;
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
lblMessage.Text = "Load at: " + DateTime.Now.ToLongTimeString();
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}


Please check out the suggestion. If you have any further questions, please
feel free to post here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Alfons,


Have you had a chance to try out the suggestion in the last reply or have
you resolved this problem? If you need any assistance, please feel free to
post here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Joined
May 25, 2011
Messages
1
Reaction score
0
problem solved !!!

Thansx Steve for the wonderful example.....got the logic and problem also solved
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top