Block Control+V in dynamically generated Textbox fields

Asked

Viewed 199 times

3

I have a GridView where I have some TextBox that are generated according to the total lines of the same.

I’d like to block the Control+V in all the TextBox.

Use the Jquery 1.4, and from what I read the method on currently used for the new Jquerys corresponds to live in the Jquery 1.4.

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

I know that each TextBox generated is also generated a ID different.

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

2 answers

1


I got it by "class" as follows.

  $(function () {
      $(".numero").live('paste', function (e) {
                e.preventDefault();
      });
  });

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 as follows:

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.

  • How to call this function in an element dynamically created Raí? Could explain better?

  • Raí you are pasting the same code I put above.

  • I didn’t realize, I made a mention of your code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.