页面加载两次由于JS code [英] page loads twice due to js code
问题描述
我有一个中继器,在这里我设置类,里面的onmouseover和onmouseout从背后code性能本格:
I have this div inside a repeater, where i set the class, onmouseover and onmouseout properties from code behind:
<div id="Div1" runat="server" class="<%# getClassProduct(Container.ItemIndex) %>" onmouseover="<%# getClassProductOver(Container.ItemIndex) %>" onmouseout="<%# getClassProductOut(Container.ItemIndex) %>">
codebehind:
codebehind:
public String getClassProduct(Object index)
{
int indexItem = Int32.Parse(index.ToString());
if (indexItem == 3)
return "produs_box produs_box_wrap overitem lastbox";
else
return "produs_box produs_box_wrap overitem";
}
public String getClassProductOver(Object index)
{
int indexItem = Int32.Parse(index.ToString());
if (indexItem == 3)
return "this.className='produs_box produs_box_wrap overitem_ lastbox'";
else
return "this.className='produs_box produs_box_wrap overitem_'";
}
public String getClassProductOut(Object index)
{
int indexItem = Int32.Parse(index.ToString());
if (indexItem == 3)
return "this.className='produs_box produs_box_wrap overitem lastbox'";
else
return "this.className='produs_box produs_box_wrap overitem'";
}
那么,问题是,我的Page_Load被激发两次,并有我有一些code,我想只执行一次:
Well, the problem is that, my Page_Load is fired twice, and there i have some code which i want to execute only ONCE:
if (!Page.IsPostBack)
{ ..code to execute once }
这code最初发射,并在页面呈现之后,它被再次调用,并执行再次,由于该js的...
This code is fired initially, and after the page is rendered, it is called again, and executed again due to that js...
任何人都可以推荐一个解决方法吗?
Anyone can recommend a workaround?
先谢谢了。
更新:只发生在Firefox。在Chrome,它工作正常...
UPDATE: happens only in Firefox. On chrome, it works fine...
解决方案:停用YSlow的....只是可怕
"Solution": deactivated YSlow....just "horrible".
推荐答案
您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcreated%28v=VS.90%29.aspx\"相对=nofollow> OnItemCreated
事件来做到这一点?
Can you use OnItemCreated
event to do that?
假设,在div是每个项目的一部分,你可以捕获到事件&放大器;做一个的FindControl
在项目
来获取句柄到 DIV
。检查的ItemIndex
&安培;如您在code-背后需要分配类。
Assuming, the div is part of each item, you could trap into the event & do a FindControl
on the Item
to get the handle to div
. Check for ItemIndex
& assign the class as you need to in code-behind.
这是否帮助呢?
这篇关于页面加载两次由于JS code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!