1

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:

 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".

Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
  • You should post the whole page, so we can see the context, which is likely where the important information exists. – John Fisher Apr 03 '10 at 17:52
  • Well, the hole page (aspx) has 350 lines of cod. If i only comment that div from above, all it's working great. – Cristian Boariu Apr 03 '10 at 17:54
  • I suggest watching it in the debugger and check the stack trace to see who is calling the code twice. – Ray Apr 03 '10 at 18:00
  • If this changes based on the browser, then it sounds like somethng in your content is causing the browser to reload. What is the content of the div? You code only shows how you handle the appearance. – Ray Apr 03 '10 at 18:38

2 Answers2

0

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?

shahkalpesh
  • 33,172
  • 3
  • 63
  • 88
0

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.