读书人

page_load被执行了多次,该如何解决

发布时间: 2012-02-01 16:58:19 作者: rapoo

page_load被执行了多次
各位,为什么在我启动页面时,被多次提交,也就是page_load被走了多次。
asp.net代码如下(page_load走了4次):

HTML code
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Login.aspx.vb" Inherits="Login" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title>login</title></head><body style="background-color: #fefefe"><form id="form1" runat="server">    <div style="top: 0px;">    <table cellpadding="0" cellspacing="0" id="main" runat="server" style="width: 100%;        height: 590px; text-align: center; background-color: #fefefe; top: 0px">        <tr>            <td style="height: 300px; vertical-align: bottom;">               <asp:ScriptManager ID="ScriptManager1" runat="server">                </asp:ScriptManager>                <asp:UpdatePanel ID="UpdatePanel1" runat="server">                <ContentTemplate>                <table cellpadding="0" cellspacing="0" id="main_up" runat="server" style="background-color: #fefefe;                    width: 100%; text-align: center">                    <!-- service logo -->                    <tr>                        <td style="background-image: url(image/backimage.gif); background-repeat:repeat-x; width: 20%; background-attachment: scroll; height: 100%;">                        </td>                        <td colspan="3" align="left" style="background-image: url(~/image/backimage.gif); background-repeat:repeat-x; width: 25%;">                            <asp:Image ID="ImageLK" runat="server" ImageUrl="~/image/LK-logo.gif" />                        </td>                        <td style="background-image: url(image/backimage.gif); background-repeat:repeat-x; width: 20%; background-attachment: scroll;">                        </td>                    </tr>                                    </table>                </ContentTemplate>                </asp:UpdatePanel>            </td>        </tr>    </table>    </div>    <div style="text-align : center;">    <asp:Label ID="Label1" runat="server" Text="Copyright© aaa, Inc." Font-Names="Verdana" Font-Size="XX-Small"></asp:Label></div>    </form></body></html>


如果去掉
HTML code
<td colspan="3" align="left" style="background-image: url(~/image/backimage.gif); background-repeat:repeat-x; width: 25%;">                            <asp:Image ID="ImageLK" runat="server" ImageUrl="~/image/LK-logo.gif" />                        </td>

那么page_load就被走了2次。

求解~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[解决办法]
诡异……
记得有一个IsPostback,可以试试
[解决办法]
vb?
[解决办法]
页面上有几个图片标签
------解决方案--------------------


探讨

vb?

[解决办法]
asp:UpdatePanel
可能是因为你使用了微软的ajax控件造成的。

[解决办法]
if(!ispostback)
[解决办法]
在load事件中
if(!isposback)
{

加入你的代码
}
[解决办法]
没有后台代码,谁也不知道你在后台干了些什么!

服务器控件都会激发Page_load的
[解决办法]
好像跟图片有关系,还有就是table,好像是一个属性不对,不知道是不是image的source不设置,或者是甚至不对,都会引起page_load走2次的

google搜 “image page_load 2次” 有答案,楼主看看。
[解决办法]
前台后台都贴一下代码。[color=#FF0000]或者楼主注释一部分,一部分的测试加断点[/color]
[解决办法]
UpdatePanel 大概是这个控件的特性,局部刷新。。可能是多个控件绑定造成的咯,没绑定一次都会造成回发
[解决办法]
LZ,这你代码,我测试的时候就调用一次啊,

我曾经遇到这个问题,挺奇怪的,莫名奇妙的调用两次,后来逐个排查,是因为引用了两JS造成的。

读书人网 >asp.net

热点推荐