page loads twice due to js code

Posted by Cristian Boariu on Stack Overflow See other posts from Stack Overflow or by Cristian Boariu
Published on 2010-04-03T17:45:54Z Indexed on 2010/04/03 17:53 UTC
Read the original article Hit count: 198

Filed under:

Hi, 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.

© Stack Overflow or respective owner

Related posts about ASP.NET