【问题标题】:pop up page , when a link button is clicked弹出页面,当点击链接按钮时
【发布时间】:2010-08-04 21:13:56
【问题描述】:
<td colspan ="2" style="width: 64px">
    <div style="float:left; padding-left:9px;">
        <asp:LinkButton ID="lnkremoveloc" runat="server" 
            OnClick="lnkremoveloc_Click" CssClass="linkclass" 
            style="cursor:pointer" Font-Underline="True" 
            Font-Bold="true" Font-Size="12px">
            Remove Location
        </asp:LinkButton>
    </div>
</td>

这是链接按钮,单击时我会从中弹出一个窗口。 弹出页面如下所示。但是当我单击此链接时,同一页面会刷新,并且我会松开保存和取消按钮,而不是打开弹出窗口。有人可以帮我吗。我不知道我在哪里做错了。非常感谢...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisableLocation.aspx.cs" Inherits="DisableLocation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%--<html xmlns="http://www.w3.org/1999/xhtml" >--%>


<script language ="javascript" type="text/javascript" >

function PopupCenter(pageURL, title,w,h) {
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);
    var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, 
            status=no, menubar=no,scrollbars=no, resizable=no, copyhistory=no, width='+w+', 
            height='+h+', top='+top+', left='+left);
} 

</script language ="javascript" type="text/javascript">


<html>
<head runat="server">
    <title>Disable Location | DealTown.com</title>
</head>

<body>
    <form id="form1" runat="server">
        <div style="display: block; background: url(images/reusable_blue_bg.jpg) repeat-x 0 -15px;border-left: #88b9c7 1px solid; border-bottom:#88b9c7 1px solid; border-top:#88b9c7 1px solid; border-right: #88b9c7 1px solid;   padding: 0px 2px;   height: 236px;  min-height: 236px;  height: auto;   margin-left: auto;  margin-right: auto;">
        <table align="center" style="width: 554px; border-top-style: none;  border-right-style: none;
            border-left-style: none; border-bottom-style: none" id="TABLE1">
            <tr >
                <td align="center" colspan="5" style="font-weight:normal;font-size:18px;margin: 0px;font-family: Arial;color: #1e7c9b;" >Disable Location</td>
            </tr>

            <asp:GridView ID="diableloc" runat="server" AutoGenerateColumns="False" 
             DataKeyNames="LocationName" DataSourceID="getGridMerchantLocationData" 
             AllowPaging="True" EnableViewState="False">
             <Columns>
            <asp:BoundField DataField="chkbox" HeaderText="Select" 
                SortExpression="Selection" />
            <asp:BoundField DataField="locname" HeaderText="Location Name" 
                ReadOnly="True" SortExpression="Locnames" />
            </Columns>
           </asp:GridView>

           <asp:ObjectDataSource ID="ProductsDataSource" runat="server" 
           OldValuesParameterFormatString="original_{0}" 
           SelectMethod="GetLocations" TypeName="string">            
           </asp:ObjectDataSource>


            </table>
              <tr>
                <td style="width: 44px; height: 63px">
                </td>
                <td style="width: 127px; height: 63px">
                </td>
                <td align="left" colspan="2" style="height: 63px; width: 196px;">
                <asp:ImageButton ID="btnDisable" runat="server" ImageUrl="~/images/save.gif" OnClick="btnDisable_Click"
                 ValidationGroup="group1" />
                 <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/cancel.gif" OnClick="btnCancel_Click" /></td>
                <td colspan="1" style="width: 92px; height: 63px">
                </td>
            </tr> 

        </div>
    </form>
    </body>
</html>

【问题讨论】:

    标签: c# javascript asp.net html


    【解决方案1】:

    听起来页面正在回发。你试过AutoPostBack="false"吗?不确定您是否需要在这里使用 LinkBut​​ton。您可以只使用带有onclick 的锚标记来调用弹出窗口吗?

    当单击 LinkBut​​ton 时,您是否有需要在服务器端执行的代码?如果你需要两者,你可以使用 OnClientClick 属性来拥有两者。 已经有一段时间了,但我认为你可以做到,如果 onclientclick 中客户端代码返回的值返回 false,则服务器代码将不会执行。

    我看不到您当前的 LinkBut​​ton 如何显示弹出窗口。

    【讨论】:

      【解决方案2】:

      使用 OnClientClick="lnkremoveloc_Click" 而不是 OnClick,其中 lnkremoveloc_Click 是打开弹出窗口的 JavaScript 函数(类似于您已经拥有的 PopupCenter)。

      【讨论】:

        【解决方案3】:

        设置onclientclick 而不是onclick。而渲染(页面加载)本身将onclientclick设置为"PopupCenter('url','title',....);return false;"

        可以在加载时设置 url、标题、宽度等。最后一部分“return false”将取消点击的效果。因此它可以防止回发。

        注意:如果您想在服务器端处理某些内容,最好不要设置 onclientclick 并使用 Response.write("&lt;script&gt;PopupCenter('url','title',....);&lt;/script&gt;");

        我希望这会有所帮助。

        这是我的第一篇文章:)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多