简体   繁体   中英

pop up page , when a link button is clicked

<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>

This is the link button from where i get a popup when clicked. The popup page is like below. But when i click this link, the same page gets refreshed and i loose Save and Cancel button instead of opening a popup. Can someone help me out. I have no idea where i am doing wrong. Thanks a lot...

<%@ 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>

Sounds like the page is posting back. Did you try AutoPostBack="false" ? Not sure you need a LinkButton here. Can you just use a anchor tag with onclick instead to invoke the popup?

Do you have code that needs to execute on the server side when the LinkButton is clicked? If you need both you can use the OnClientClick property to have both. It has been a while, but I think you can make it so the server code won't execute if the value returned from the client side code in onclientclick returns false.

I don't see how your current LinkButton shows the popup.

代替OnClick使用OnClientClick="lnkremoveloc_Click" ,其中lnkremoveloc_Click是打开弹出窗口的JavaScript函数(类似于PopupCenter之类的东西)。

Set the onclientclick instead of onclick . And while rendering(page load) itself set the onclientclick as "PopupCenter('url','title',....);return false;"

The url, title, width, etc can be set on load. The last part "return false" will annul the effect of click. Thus it prevents post back.

Note: If you want something to be processed at server side, its better not to set the onclientclick and use Response.write("<script>PopupCenter('url','title',....);</script>");

I hope that helps.

This is my first post :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM