27 April, 2012

Determine whether Caps Lock is on in ASP.net Page by JavaScript


Here I used a simple Textbox in ASP.net page and used Javascript to determine whether Caps Lock is on or off.
I have used the following Javascript code in between head  tag.
 function isCapslock(e) {

            e = (e) ? e : window.event;

            var charCode = false;

            if (e.which) {
                charCode = e.which;
            } else if (e.keyCode) {
                charCode = e.keyCode;
            }

            var shifton = false;
            if (e.shiftKey) {
                shifton = e.shiftKey;
            } else if (e.modifiers) {
                shifton = !!(e.modifiers & 4);
            }

            if (charCode >= 97 && charCode <= 122 && shifton) {
                document.getElementById("txtCapsMsg").value = "Caps Lock is on";
                return true;
            }

            if (charCode >= 65 && charCode <= 90 && !shifton) {
                document.getElementById("txtCapsMsg").value = "Caps Lock is on";
                return true;
            }

            document.getElementById("txtCapsMsg").value = "Caps Lock is off";
            return false;

        }

I have also used two text box in ASP.net page. One for input and another for displaying message whether Caps Lock is on or off.


<form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    Message :
                td>
                <td>
                    <input type="text" id="txtCapsMsg" />
                td>
            tr>
            <tr>
                <td>
                    Input Text :
                td>
                <td>
                    <asp:TextBox ID="txtInputCaps" runat="server" onkeypress="isCapslock(event)">asp:TextBox>
                td>
            tr>
        table>
    div>
    form>

Now input some text in input textbox. Message will be showed in txtCapsMsg textbox whether Caps Lock is on or off.

20 comments:

  1. this is not working in my project . how can i add/load external javascript file in asp.net and i did not find any onkeypress event in asp.net .

    ReplyDelete
  2. onkeypress is not server side event. It is client side event. Just copy the code and try to run. Could you please send me the error which you have found?

    ReplyDelete
  3. Hasan very very thanks...

    ReplyDelete
  4. A Valuable post,it really useful.
    C# Training
    best c sharp training in chennai

    ReplyDelete
  5. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    microsoft azure training in bangalore
    rpa interview questions and answers
    automation anywhere interview questions and answers
    blueprism interview questions and answers
    uipath interview questions and answers
    rpa training in bangalore

    ReplyDelete
  6. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    Best Devops Training in pune
    Devops Training in Bangalore
    Power bi training in Chennai

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites!..thanks lot!!

    Java training in Chennai

    Java Online training in Chennai

    Java Course in Chennai

    Best JAVA Training Institutes in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Training

    Java Online Training

    ReplyDelete
  9. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    AWS Course in Chennai

    AWS Course in Bangalore

    AWS Course in Hyderabad

    AWS Course in Coimbatore

    AWS Course

    AWS Certification Course

    AWS Certification Training

    AWS Online Training

    AWS Training


    ReplyDelete
  10. I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..

    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore


    ReplyDelete
  11. mage and Video Editing. More and more jobs are looking for basic photo and video editing skills, so it's useful to spend your free time — whether it's weekends or a summer — mastering at least one editing program. ...keep up!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  12. Flvto is superb Reddit video downloader. It helps convert Reddit videos to mp3, and of course video file download includes audio track. Flvto Youtube Downloader Download

    ReplyDelete
  13. Tally ERP 9 Crack 2022 With Latest Version Full Download. This is easy software which is perfect for all users involved in improved business .Tally GST Crack

    ReplyDelete
  14. Majority sell away wife chair speak. Each senior somebody career now necessary material. Personal country already them better.top 10 news today

    ReplyDelete