当通过另一个 aspx 页面的 javascript 打开一个 aspx 时,不会触发 PageLoad 事件

发布于 2024-10-13 23:43:58 字数 219 浏览 12 评论 0原文

我有一个包含 2 个 aspx 页面的 aspx 应用程序。使用 JavaScript 单击第一个 aspx 页面中的按钮即可打开第二个 aspx 页面。问题是,当打开第二个 aspx 页面时,其 Page_load 事件没有触发。仅当我刷新第二个页面时,才会触发第二个 aspx 页面的 page_load 事件。

请让我知道可能是什么问题以及如何触发 page_load 事件。

提前致谢

I have an aspx application with 2 aspx pages. Second aspx page will get opened on click of a button in first aspx page using JavaScript. The problem is, when the second aspx page is getting opened, its Page_load event is not firing. Only when I refresh the second page, page_load event of second aspx page is fired.

Please let me know what might be the problem and what is to be done to fire the page_load event.

Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2024-10-20 23:43:58

在这种情况下(从 window.open() 调用 aspx 页面),您必须在页面的 OnInit 事件中手动附加 Page_Load 事件:

override protected void OnInit(EventArgs e)
{
    this.Load += new EventHandler(Page_Load);
    base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
  // your code here 
}

参考: http://www.vbforums.com/showthread.php?t=249689

In this case (calling the aspx page from window.open()) you have to attach the Page_Load event manually in the page's OnInit event:

override protected void OnInit(EventArgs e)
{
    this.Load += new EventHandler(Page_Load);
    base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
  // your code here 
}

reference: http://www.vbforums.com/showthread.php?t=249689

相权↑美人 2024-10-20 23:43:58

您是否使用 showModalDialog 打开页面?如果是这样,那么就是缓存问题。

如果是这样,有多种解决方法。有些人建议在 URL 的查询字符串中添加一个随机数或日期时间,这样它就不会被缓存。

就我个人而言,我喜欢这种方式。请参阅此处 http://msdn.microsoft .com/en-us/library/c4yy9w70.aspx 确保将其设置为 HttpCacheability.NoCache

Are you opening the page with showModalDialog? if so, then it's the caching issue.

If so there are muliple work arounds. Some suggest to add a random number or datetime to the query string to the URL so that it does not get cached ever.

Personally, I like this way of doing it.Refer here http://msdn.microsoft.com/en-us/library/c4yy9w70.aspx Make sure you set it to HttpCacheability.NoCache

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文