Search code examples
asp.netajaxcontroltoolkit

a button redirects to another page instead of calling the callback function


i have the most peculiar behavior. I'm using ajaxcontrol toolkit to display modal popup window which has a form on it. this popup window is activated from a webpage which contains asp:linkbutton on it (with OnClientClick="aspnetForm.target ='_blank';" on it, i don't think so but maybe this is relevant). now, if i click the link then another tab is opened with the new page on it. when I am back to the original tab and activating this modal popup, if i click on the cancel button (which i have there) then the callback function is not even called (this callback just suppose to hide the popup window) and my current tab is redirected to the same page the asp:linkbutton was referring to.

Some code:

i have a page containing the following asp:linkbutton:

<asp:LinkButton ID="lbToBuy" runat="server" CssClass="ItemURLStyle" CausesValidation="false"
OnClientClick="aspnetForm.target ='_blank';">buy it>></asp:LinkButton>

this is a line from a user control which i dynamically add to some search result page. The code behind is:

lbToBuy.PostBackUrl = "~/pages/PassagePage.aspx?i=" + itemInfo.ItemID.ToString();

now, I have another user control added to original page which is a search bar for items from my website:

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:LinkButton ID="lbAdvancedSearch" runat="server" Style="color: #f6f7ff; font-family: Arial;
                    font-size: 12px; text-decoration: underline;">Search options</asp:LinkButton>
                <asp:ModalPopupExtender runat="server" ID="AdvSearchPopupModal" TargetControlID="lbAdvancedSearch"
                    PopupControlID="pnlAdvSearch" BackgroundCssClass="modalBackground" DropShadow="false"
                    RepositionMode="RepositionOnWindowScroll">
                </asp:ModalPopupExtender>
                <asp:Panel ID="pnlAdvSearch" runat="server" CssClass="modalPopup" Style="display: none;">
                    <asp:Panel runat="server" ID="Panel3" CssClass="modalHeader">
                        Advanced search
                    </asp:Panel>
                    <div id="SearchFormWrap">
                        <div id="SearchFormBox">
                            <br />
                            <table cellspacing="5">
                                <colgroup>
                                    <col width="100px;" align="left" />
                                    <col width="300px;" />
                                </colgroup>
                                <tbody>
SOME UNIMPORTANT SEARCH CRITERION HERE
                                </tbody>
                            </table>
                            <div style="width: 280px; margin: auto; padding-bottom: 15px;">
                                <br />
                                <div style="width: 210px; height: 30px; margin: auto;">
                                    <asp:Button ID="btnQuitAdvSearch" runat="server" CssClass="myButtonShape" Style="font-size: 14px;
                                        float: left; height: 25px; width: 100px;" OnClick="btnQuitAdvSearch_Click" CausesValidation="false"
                                        Text="Cancel" />
                                    <div style="width: 3px; height: 25px; float: left;">
                                    </div>
                                    <asp:Button ID="btnAdvSearch" runat="server" class="myButtonShape" Style="font-size: 14px;
                                        float: left; height: 25px; width: 100px;" OnClick="btnAdvSearch_Click" OnClientClick="return btnSearch_OnClientClick();"
                                        CausesValidation="true" Text="Search" />
                                </div>
                            </div>
                        </div>
                    </div>
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>

The codebehind:

protected void btnQuitAdvSearch_Click(object sender, EventArgs e)
{
    this.AdvSearchPopupModal.Hide();
}

Now, when I press the link in my page another tab is opened with the directed link as expected. When I am back to original page and I press the advanced search button I get this modal popup displaying the search criteria. if I press the 'search' button everything goes as expected and a new search is formed, but if I press the 'cancel' button the page is redirected to the last link I was clicking (in the current tab, i.e., replaces the original page). I put a breakpoint at the btnQuitAdvSearch_Click function but it is never been called.

Any ideas?


Solution

  • OK. now i figured things out. I was very sloppy. Although Drew provide me with a solution to one case this still didn't explain the problem. The entire solution is different. The thing is that I used the suggestion this guy provided here and used OnClientClick="aspnetForm.target ='_blank';" but I didn't implement the fix he suggested to add to body onload (there). now everything works fine.

    Thanks a lot Drew.