本文介绍了当我点击页面上的按钮,为什么一个的.aspx页面加载两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在.aspx页上的按钮点击,页面加载两次。在第一次加载时,页面的IsPostBack属性为true,并且在第二负载,此属性将成为虚假的,这是我的网站的一个问题。

When clicking on a button in a .aspx page, the page loads twice. In the first load, the page's IsPostBack property is true and on the second load, this property will become false, which is a problem for my website.

有没有人有它为什么两次加载任何想法?

Does anyone have any ideas why it is loading twice?

推荐答案

以下是投递的可能的手段两次:

Following are the possible means of postback twice:

1,请检查您是否未明确从客户端制作回发。

1- please check that you are not explicitly making postback from client-side.

2 - 请检查你的网页img标签src属性不为空。因为当你创建一个img元素,并留下其src属性空的,它会自动设置为您的根目录下(如http://www.mysite.com/)。因此,当Page_Load事件火第一次,与原来的回发(POST请求)的Page.IsPostBack将与真进行设置。但是,当服务器响应将在客户端被解析,另一个GET请求将被解雇到服务器,请求图像​​(其SRC设置为默认根URL),这就是为什么Page.IsPostBack属性会与用于第二时间假值初始化。

2- Please check that in your page img tag src attribute is not empty. Because when you create an img element and leave its src attribute empty, it will automatically set as your root directory (e.g. "http://www.mysite.com/"). Therefore, when the Page_Load event fire for the first time, with the original post back (POST request) the Page.IsPostBack will be set with "true". But when the server response will be parsed at the client side, another GET request will be fired to the server, requesting that image (that its src was set to the root url by default) and this is why the Page.IsPostBack property will be initialized with "false" value for the second time.

这篇关于当我点击页面上的按钮,为什么一个的.aspx页面加载两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:14