c# - 使用按钮单击使用零剪贴板复制文本

标签 c# asp.net web-applications zeroclipboard

刚注意到它在我禁用 CSS 时有效 谁能解释为什么?

我正在使用零剪贴板将文本框的值复制到剪贴板。

我能够让它在普通的 HTML 页面上工作,但是当我在 aspx 页面上应用相同的代码时,它无法按预期工作。

让我先解释一下它是如何在普通的 html 页面上工作的。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Locker.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     <asp:Button ID="Button1" runat="server" Text="Button" />      
    </form>

             <script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script>
             <script type="text/javascript" src="Scripts/jquery.zclip.js"></script>
             <script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script>
              <script>
                  $(document).ready(function () {
                      $('#<%=Button1.ClientID%>').zclip({
                          path: 'ZeroClipboard.swf',
                          copy: function () { return $('#<%=TextBox1.ClientID%>').val(); }
                      });
                  });
              </script>
</body>
</html>

它将文本框中输入的任何内容复制到剪贴板。

当我右键单击该按钮时,我可以看到它已连接到 Zeroclipboard 闪存。 enter image description here

现在,如果我在链接到母版页的 aspx 页面上实现相同的功能,它就不起作用,

我认为 zerocliboard 没有初始化。

当我右击按钮时,我看到了不同的东西。 (必须如上所述才能使这项工作。)

enter image description here

aspx页面代码如下:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="searchResult.aspx.cs" Inherits="Locker.searchResult" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .auto-style1 {
            color: #FFFFFF;
            font-size: large;
        }
        .auto-style2 {
            color: #000000;
        }
        .auto-style3 {
            color: #000000;
            font-size: large;
        }
    </style>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

        &nbsp;<p>

        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong> <span class="auto-style3">Information</span><span class="auto-style1">&nbsp;&nbsp;&nbsp;</span></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
         <div style="width:70%; margin: auto auto; text-align:left;">
          <asp:Panel ID="Panel1" runat="server">
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label4" runat="server" style="font-weight: 700; font-size: large" Text="Details for :" CssClass="auto-style2"></asp:Label>
            <asp:Label ID="Label5" runat="server" style="font-weight: 700; font-size: large; color: #0000FF"></asp:Label>
            <br />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="False" style="font-weight: 700; font-size: large" Text="Password :" CssClass="auto-style2"></asp:Label>
            &nbsp;<asp:TextBox ID="TextBox2" runat="server" BorderStyle="Solid"  Enabled="False" Font-Size="Medium" ForeColor="Black" Width="213px"></asp:TextBox>

              &nbsp;

              <asp:Button ID="Button3" runat="server" Text="Button" />              
              <input type="text" id="test_description" value="hi" />

             <script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script>
             <script type="text/javascript" src="Scripts/jquery.zclip.js"></script>
             <script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script>
              <script>
                 window.onload = $(document).ready(function () {
                      $('#<%=Button3.ClientID%>').zclip({
                          path: 'ZeroClipboard.swf',
                          copy: window.onload = function () { return $('#<%=TextBox2.ClientID%>').val(); }
                      });
                  });
              </script>
            <br />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
            <asp:Label ID="Label6" runat="server" style="font-weight: 700; font-size: large" Text="Description :" CssClass="auto-style2"></asp:Label>
            &nbsp;<asp:TextBox ID="TextBox5" runat="server" BorderStyle="Solid" Enabled="False" Font-Size="Medium" Height="48px" TextMode="MultiLine" Width="213px"></asp:TextBox>
            <br />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label7" runat="server" style="font-weight: 700; font-size: small" Text="Last Editor was " CssClass="auto-style2"></asp:Label>
            <asp:Label ID="Label8" runat="server" style="font-weight: 700; font-size: small" CssClass="auto-style2"></asp:Label>
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Edit" Width="97px" />
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" Visible="False" Width="97px" />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="Label12" runat="server" style="font-weight: 700; font-size: large; color: #0000FF" Visible="False"></asp:Label>
            <br />
            <br />
            <br />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;
    </asp:Panel>

         </div>
</asp:Content>

有谁知道问题出在哪里,如何解决?

检查 HTML 页面的结果 enter image description here

检查普通页面的结果 enter image description here

最佳答案

查看“Inspect Result from Normal Page”的输出,我可以看到“TextBox2”被禁用(而它应该被启用)并且它还应用了 CSS 类“aspNetDisabled”。很可能是“aspNetDisabled”类导致 ZeroCopy 工具失败,因为当您关闭 CSS 时,功能会起作用。

请注意“检查来自 HTML 页面的结果”中的“TextBox1”如何未被禁用。

因此,要使其正常工作,请确保 ASPX 页面中的“TextBox2”已将“Enabled”设置为 True。

还要确保在使用它的浏览器上安装了 Flash,因为 ZeroClipboard 使用“不可见的 Adob​​e Flash 电影”。

最后,删除“window.onload”,即将代码更改为:

$(document).ready(function () {
 $('#<%=Button3.ClientID%>').zclip({
  path: 'ZeroClipboard.swf',
  copy: function () { return $('#<%=TextBox2.ClientID%>').val(); }
 });
});

因为我认为它不适用于 ZeroClipboard 库。

关于c# - 使用按钮单击使用零剪贴板复制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19027424/

相关文章:

c# - 如何使构造函数只能由基类访问?

c# - 我可以向现有的分部类添加错误处理吗?

sql - 如何将日期与当前时间一起保存到数据库中?

asp.net - 在运行时更改 web.config 连接字符串的最佳方法是什么?

java - java web应用的增量部署

java - JavaFx 2.0 在 Web 应用程序客户端的可移植性如何(以及是否高效)?

c# - Newtonsoft JSON- 与 DataSet 之间的转换会导致 Decimal 变为 Double?

c# - 如何更改不同构建配置的可执行文件名和图标?

javascript - 选择文件后显示图像

c# - 详细信息 GridView 意外刷新整个页面