简体   繁体   中英

onpaste event on asp.net textbox in internet explorer not working

this is my textbox:

<asp:TextBox ID="txtBoxFlagDes" TextMode="MultiLine" runat="server" MaxLength="30" Width="150px" onkeypress="return this.value.length<=30"></asp:TextBox>

here's the script:

<script src="../Scripts/jquery-3.1.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#txtBoxFlagDes").on("input", function () {
            LimtCharacters(this, 30);
        });
    });
    function LimtCharacters(txtMsg, CharLength) {
        chars = txtMsg.value.length;
        if (chars > CharLength) {
            txtMsg.value = txtMsg.value.substring(0, CharLength);                
        }
    }
</script>

when the user copies some text and paste into textbox then it takes whole text from the clipboard in short the script is not working. not getting the problem

As per the Browser's compatibility of input event it will not support IE<9

Feature             Chrome     Firefox     Internet Explorer    ....
Basic support       (Yes)      2           9                     

Your script is checking the input by user or keypress event. but when copied text pasting into the Test box this event is not going to fire. So obviously your scipt will not work in that case.

Might be after past the text in the text box you can validate that text on lost focus.

Hope this helps.

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