Click here to Skip to main content
15,891,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one :),

I have a textbox, on F2 press i want to perform some operation. So, i want to send the keycode from page behind specifically in page load because i am using client call back mechanism to rebind the gridview and show model popup window on textbox F2 press. So when using this through javascript, it is unable to find the keycode(window.event.keyCode). So i want to check that the keycode is 113 in page load or raisecallbackevent. Plz give some suggetions or send me the related code.

thanks
Posted
Updated 3-Jun-10 0:15am
v2

1 solution

Hopefully this is what you are looking for...

C#
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
{
    protected string returnValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        string cbReference =
        Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
        string callbackScript = "function CallServer(arg, context) { " + cbReference + ";}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        if (eventArgument == "113") // F2 Pressed
        {
            // Do Whatever You Want here
            returnValue = "F2 Was Pressed";
        }
        else
        {
            returnValue = "Some Other Key Was Pressed";
        }
    }
    public string GetCallbackResult()
    {
        return returnValue;
    }
}


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

    <script language="javascript">
        function txtSearch_onkeyup() {
            document.getElementById("ResultsSpan").innerHTML = "";
            if (window.event.keyCode) {
                CallServer(window.event.keyCode, "");
            }
        }
        function ReceiveServerData(rValue) {
            document.getElementById("ResultsSpan").innerHTML = rValue;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtSearch" NAME="txtSearch" runat="server" onkeyup="javascript:txtSearch_onkeyup()"></asp:TextBox>
        <br />
        <span id="ResultsSpan" runat="server"></span>
    </div>
    </form>
</body>
</html>


Enjoy,
Ashish Mehta
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900