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开发者_StackOverflow.ItemIndex) %>" onmouseover="<%# getClassProductOver(Container.ItemIndex) %>" onmouseout="<%# getClassProductOut(Container.ItemIndex) %>">
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'";
}
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 }
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?
Thanks in advance.
UPDATE: happens only in Firefox. On chrome, it works fine...
"Solution": deactivated YSlow....just "horrible".
Can you use OnItemCreated
event to do that?
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.
Does that help at all?
I replaced the Response.Redirect
with Server.Transfer
because it was suggested to be the new way of doing things. Since then, the pages load twice and the Back-button in Chrome returns to the previous page and immediately back to the current page.
I replaced the Server.Transfer
with Response.Redirect
, and all was back to normal. I hope this helps someone.
精彩评论