image button doesn't work correctly in datalist
<p>i have an image button in datalist to open a new page to send mail, but when i click on it for the first time , it doesn't work , it works when click for the second time , i use update panel inside datalist . here's the code </p>

<pre><code>&lt;asp:UpdatePanel ID="up1" runat="server"&gt;
    &lt;ContentTemplate&gt;          
        &lt;asp:ImageButton ID="ImgBtnMail" runat="server" ImageUrl="../../../../Icons/Send-Email.jpg" 
             Width="22" Height="18" CommandName="DoMail" 
             CommandArgument='&lt;%#DataBinder.Eval(((System.Web.UI.WebControls.DataListItem)(Container)).DataItem, "AdID")%&gt;' /&gt;
    &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
</code></pre>

<p>and the code behind :</p>

<pre><code> protected void DLAds_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if(e.CommandName=="DoMail")
        {
            string TargetPage = "window.open('SendMail.aspx?',null,'height=150, width=150,left=500 ,top=300 ,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');";
            ImageButton MailBtn = (ImageButton)e.Item.FindControl("ImgBtnMail");
            MailBtn.Attributes.Add("onclick", TargetPage);
        }
    }
</code></pre>
