Block Control + V in dynamically generated TextBox fields

3

I have a GridView where I have several TextBox that are generated according to their total rows.

I would like to block Control+V in all TextBox .

I use Jquery 1.4 , and so I read the on method currently used for the new Jquerys is the live in Jquery 1.4 .

I tried the following code but I did not succeed and not the error in the log.

I know that every TextBox generated is also generated ID different.

Can anyone help me?

  

My Jquery

$("#<%=tbNaoAtende.ClientID%>").live('paste',function (e) {
    e.preventDefault();
});
$("#<%=tbNaoAtendeInic.ClientID%>").live('paste', function (e) {
    e.preventDefault();
});
$("#<%=tbAtendeRess.ClientID%>").live('paste', function (e) {
    e.preventDefault();
});
$("#<%=tbAtende.ClientID%>").live('paste', function (e) {
    e.preventDefault();
});
  

My aspx

<asp:GridView ID="rptListaVerificacao" runat="server" PageSize="50" AutoGenerateColumns="false" SkinID="gridLV" AllowPaging="True" Width="100%">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Table ID="tbAtendimentos" runat="server" Style="font-weight: bold; border: solid 1px #c0c0c0;"
            CellPadding="5">
                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Resource, nao_atende%>"></asp:Literal>:</asp:TableCell>
                        <asp:TableCell Style="padding-right: 20px;">
                            <asp:TextBox ID="tbNaoAtende" runat="server" Width="40px" CssClass="numero"></asp:TextBox></asp:TableCell>
                        <asp:TableCell>
                            <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:Resource, nao_atende_iniciativa%>"></asp:Literal>:</asp:TableCell>
                        <asp:TableCell Style="padding-right: 20px;">
                            <asp:TextBox ID="tbNaoAtendeInic" runat="server" Width="40px" CssClass="numero"></asp:TextBox></asp:TableCell>
                        <asp:TableCell>
                            <asp:Literal ID="Literal9" runat="server" Text="<%$Resources:Resource, atende_ressalva%>"></asp:Literal>:</asp:TableCell>
                        <asp:TableCell Style="padding-right: 20px;">
                            <asp:TextBox ID="tbAtendeRess" runat="server" Width="40px" CssClass="numero"></asp:TextBox></asp:TableCell>
                        <asp:TableCell>
                            <asp:Literal ID="Literal10" runat="server" Text="<%$Resources:Resource, atende%>"></asp:Literal>:</asp:TableCell>
                        <asp:TableCell Style="padding-right: 20px;">
                            <asp:TextBox ID="tbAtende" runat="server" Width="40px" CssClass="numero"></asp:TextBox></asp:TableCell>
                        <asp:TableCell>
                            <asp:LinkButton ID="lbtAtualizaAtendimento" runat="server" Text="<%$Resources:Resource, atualiza_atendimento%>"
                        OnClick="lbtAtualizaAtendimento_Click"></asp:LinkButton></asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
    
asked by anonymous 29.01.2015 / 13:51

2 answers

1

I got it by "class" as follows.

  $(function () {
      $(".numero").live('paste', function (e) {
                e.preventDefault();
      });
  });
    
29.01.2015 / 14:53
0

You can use a javascript function to do this, for example:

 function Verificar()
 {
  var ctrl=window.event.ctrlKey;
  var tecla=window.event.keyCode;
  if (ctrl && tecla==67) {alert("CTRL+C"); event.keyCode=0; event.returnValue=false;}
  if (ctrl && tecla==86) {alert("CTRL+V"); event.keyCode=0; event.returnValue=false;}
 }

Since you are using JQuery you can do the following:

When creating the textbox:

 System.Web.UI.WebControls.TextBox txt = new System.Web.UI.WebControls.TextBox();
 txt.CssClass = "numero";

Use the JQuery function as quoted.

    
29.01.2015 / 14:37