1

很抱歉我重复这个问题。相反,我不得不重复一遍。上次我发这个,我没有得到答案。我google了3个多小时,找不到答案。这是链接按钮和模式弹出窗口的 html。链接按钮位于选项卡面板内/上,并且自动回发设置为 true。

<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClick="lnkAddNewAddress_Click">Click Here To Add New Address</asp:LinkButton>
                                        <asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
                                            DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
                                            ViewStateMode="Enabled" >
                                        </asp:ModalPopupExtender>

我希望链接按钮的 clickevent 不会发生。但是单击链接确实会打开模态弹出扩展器(这也是我想要的)......我如何进入点击事件。我知道这里避免了回发,因为模态弹出窗口可能......但我没有解决方案......

保存按钮上的代码:

  if(hdnfld.Value.ToString()!=null)
        { 
            if(hdnfld.Value.ToString()=="Save")
        {
            SaveNewAddress(); 

        }
        else
        {
            UpdateAddress();

        }




 <%@ Page StylesheetTheme="" Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="frmMyAccountMyProfile.aspx.cs"   Inherits="WebApplication1.frmMyAccountMyProfile" %>

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  <script type="text/javascript">

    function CheckType(type) 
    {
        document.getElementById("hdnfld").value = type;
        alert(document.getElementById("hdnfld").value);
        return false;
    }



</script>
<link href="Styles/myStyleSheet.css" rel="stylesheet" type="text/css" />

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="divwrap">
    <table style="width: 100%; margin-right: 0px;">
        <tr>.........
<td>
        &nbsp;<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('Save');">Click Here To Add New Address</asp:LinkButton>
       <asp:HiddenField ID="hdnfld" runat="server" />
  <asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
                                                        ViewStateMode="Enabled">
                                                    </asp:ModalPopupExtender>

  &nbsp;...........
                                                <asp:Button ID="btnEdit" runat="server" CssClass="roundcorner btn" OnClick="btnEdit_Click" OnClientClick="return CheckType('Edit');" Text="Edit" />
                                                    &nbsp;
                                                    <asp:Panel ID="pnlMyAddressBook" runat="server" BackColor="White" CssClass="roundcorner">
4

2 回答 2

1

如果你真的想在后面的代码中保留一些价值,你可以使用隐藏字段而不是视图状态。您可以在客户端以及后面的代码中访问隐藏字段。

 <asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('save');">Click Here To Add New Address</asp:LinkButton>
<asp:HiddenField ID="hdf_type" runat="server" />

Javascript代码

function CheckType(type) {
        document.getElementById("hdf_type").value = type;
         return false;
    }

单击保存按钮时访问代码中的值,并根据隐藏字段中的值执行您的操作保存或更新。

hdf_type.Value.ToString();

为您提供更多帮助

HTML 文件应如下所示

下面我发布了对我来说很好的整个代码。

<head runat="server">
<title></title>
<script type="text/javascript">
    function CheckType(type) {
        document.getElementById("hdf_type").value = type;
        alert(document.getElementById("hdf_type").value);
        return false;
    }
</script>
 </head>
 <body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>


    <asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('save');">Click Here To Add New Address</asp:LinkButton>

    <asp:Button ID="btn" runat="server" OnClientClick="return CheckType('edit');" Text="Click Here To Add New Address" />

    <asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
        DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
        ViewStateMode="Enabled">
    </asp:ModalPopupExtender>

    <div id="pnlMyAddressBook" style="height: 100px; width: 100px; display: none; background-color: Gray">
         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />

    </div>
    <asp:HiddenField ID="hdf_type" runat="server" />
</div>
</form>

在后面的代码中获得价值:

在此处输入图像描述

于 2013-03-30T07:12:21.447 回答
0

试试这个:

<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClick="lnkAddNewAddress_Click">Click Here To Add New Address</asp:LinkButton>

<asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
        DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="btnHidden">
    </asp:ModalPopupExtender>

<asp:Button ID="btnHidden" runat="server" style="Display:none;" Text="Button"/>

在后面的代码中:

protected void lnkAddNewAddress_Click(object sender, EventArgs e)
    {
        lnkAddNewAddress_ModalPopupExtender.Show();

    }
于 2013-03-30T07:00:58.330 回答