当我点击linkBut​​ton xyz打开一个新窗口时,ASP.Net LinkBut​​ton打开页面页面x.asp

时间:2012-01-30 05:54:38

标签: javascript asp.net

我有一个带有LinkBut​​ton的asp.net网页表单,例如Comment |电子邮件|下载|打印。

我使用jQuery在Ajax Modal Popup中打开Comment(Comment.asx)和Email(EmailArticle.aspx)表单。一切正常,除非我点击打印 LinkBut​​ton它将页面打开为新窗口,但在主页面上它也从PageXYZ.aspx移动到EmailArticle.aspx页面。

我不确定我检查的代码有什么问题我可以找到任何错误我必须设置一些属性,以便当我点击下载或打印它打开新闻窗口但保持邮件页面相同

的JavaScript

<script type="text/javascript" >
    jQuery(document).ready(function () {
        //Load EMail Form
        $("#<%=pnlEmailArticleForm.ClientID %>").load("EmailArticle.aspx", function () {
        //alert("Email Form has been loaded successfully!")
        });

         //For printing
         function CallPrint() {
             window.open('PrintArticle.aspx?articleID=<%=Request["articleID"] %>', 'Email', 'width=690, height=650,left=100, top=100, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no,fullscreen=no');
         }
    </script>

Ajax模式弹出窗口的HTML代码

<asp:ModalPopupExtender ID="mpShowCommentPopUp" runat="server" TargetControlID="lnkBtnComment" PopupControlID="pnlComment"
 BackgroundCssClass="modalBackground" CancelControlID="imgBtnClose" RepositionMode="None"></asp:ModalPopupExtender>

     <asp:Panel ID="pnlComment" runat="server" BackColor="White" Height="490px" Width="520px" style="display:none">
         <div id="commentForm" class="commentForm">
            <div id="divClose" class="commentClose">
                <asp:ImageButton ID="imgBtnClose" runat="server" ImageUrl="~/images/close.png" onclick="imgBtnClose_Click" CausesValidation="False"  />
            </div>
            <!-- comment Form -->
            <asp:Panel ID="pnlCommentForm" runat="server" Visible="true">

            </asp:Panel>
            <!-- comment Form -->
        </div>
    </asp:Panel>
</div>

<div>
    <asp:ModalPopupExtender ID="mpShowEmailArticlePopup" runat="server" TargetControlID="lnkBtnEmail" PopupControlID="pnlEmailArticle"
     BackgroundCssClass="modalBackground" CancelControlID="imgBtnCloseEmailPopup" RepositionMode="None"></asp:ModalPopupExtender>
          <asp:Panel ID="pnlEmailArticle" runat="server" BackColor="White" Height="450px" Width="520px" >
             <div id="emailArticle" class="EmailArticleForm">
                 <div id="closeEmailArticle" class="commentClose">
                    <asp:ImageButton ID="imgBtnCloseEmailPopup" runat="server" ImageUrl="~/images/close.png" onclick="imgBtnCloseEmailPopup_Click" CausesValidation="False"  /> 
                 </div>
                 <!-- Email Form -->
                 <asp:Panel ID="pnlEmailArticleForm" runat="server" Visible="true">

                 </asp:Panel>
                 <!-- Email Form -->
                 </div>
        </asp:Panel>
</div>

HTML链接按钮代码

   <!-- Article Details Section footer -->
    <div id="divArticleDetailsFooter"  class="divArticleDetailsFooter">
    <div id="divlblComment" class="imgTArticleDetailsFooter">
    <asp:Image ID="imgComment" runat="server" ImageUrl="~/images/comment.png"  />
    <asp:LinkButton ID="lnkBtnComment" runat="server" onclick="lnkBtnComment_Click" 
CssClass="divArticleDetailsFooterLabels" CausesValidation="False" >Comment</asp:LinkButton>

    </div>
<div id="divlblEmail" class="imgTArticleDetailsFooter">
<asp:Image ID="imgEmail" runat="server" ImageUrl="~/images/email.png" />
<asp:LinkButton ID="lnkBtnEmail" runat="server" 
CssClass="divArticleDetailsFooterLabels" CausesValidation="False" >Email</asp:LinkButton>
</div>
<div id="divlblDownload" class="imgTArticleDetailsFooter">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" />
<asp:LinkButton ID="lnkBtnDownload" runat="server" 
CssClass="divArticleDetailsFooterLabels" CausesValidation="False" >Download</asp:LinkButton>
</div>
<div id="divlblPrint" class="imgTArticleDetailsFooter">
<asp:Image ID="imgPrint" runat="server" ImageUrl="~/images/print.png" />
<asp:LinkButton ID="lnkBtnPrint" runat="server" OnClientClick="CallPrint()" 
CssClass="divArticleDetailsFooterLabels" CausesValidation="False" >Print</asp:LinkButton>
</div>
</div>  
<!-- Article Details Section footer -->

代码背后的代码

protected void lnkBtnComment_Click(object sender, EventArgs e)
{
    this.mpShowCommentPopUp.Show();
}
protected void imgBtnClose_Click(object sender, ImageClickEventArgs e)
{
    this.mpShowCommentPopUp.Hide();
}
protected void imgBtnCloseEmailPopup_Click(object sender, ImageClickEventArgs e)
{
    this.mpShowEmailArticlePopup.Show();
}

1 个答案:

答案 0 :(得分:0)

语句return false;应该用于防止诸如锚点(链接)之类的元素的默认行为。当您在具有href属性的A标记上定义onclick时,如果onclick代码没有特别返回false,浏览器将继续执行href部分。

所以,我的猜测是你的onclick处理程序启动回发(因为它们是LinkBut​​tons),它可以在服务器上执行其onclick事件,该事件旨在重定向到另一个页面(或通常执行的其他一些代码) ,你可以通过逐步了解。

因此,请尝试:将return false添加到CallPrint