Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ASP.NET Forums / General ASP.NET / Web Forms / Key Pressing Events in VB.

Net

Key Pressing Events in VB.Net[Answered]


3 replies
Last post Dec 05, 2008 03:08 AM by os123

Key Pressing Events in VB.Net


Dec 04, 2008 11:42 PM | sureshkumar.veesam

Hai Every one.

Employee ID(Textbox)  is there, I have to press F1 key in that textbox, after pressing F1 key  a GridView should be displayed ( POP UP ) . How to write code for key pressing
events. Anyone help me plzzz. It is very urgent, for  my project.

Thanks in Advance

.NET 2.0 VISUAL STUDIO 2005 ASP.NET 2.0 GRIDVIEW TEMPLATE VISUAL BASIC.NET VISUAL STUDIO WEB FORMS "ASP.NET 2.0" VISUAL STUDIO 2005 2008 ASP .NET 2.0 VB.NET EMAIL FORMS

ASP .NET 2. 0 VISUAL STUDIO.NET

Re: Key Pressing Events in VB.Net


Dec 05, 2008 12:02 AM | shobhit rai

hello suresh try some thing like this

function allowalpha(objevent)
{
var keypressed=objevent.keyCode;if (keypressed==37)  'you need to search on internet for key code of F1 and replace that  with 37
{

window.showModalDialog('msgboxpopup.aspx?msg=Special Characters not allowed.&mode=OTH','','dialogHeight:120px;dialogWidth:230px;status:no;help:no');

return false;
}

else

return true;
}

and on page load call like this

txtcity.Attributes.Add("onkeypress", "return allowalpha(event);")

Re: Key Pressing Events in VB.Net


Dec 05, 2008 12:14 AM | Neolsoft

Hi,

Attach onkeypress event to the textbox control and specify the javascript function to check the event keycode. If the keycode is of F1, write the code to display the popup
page.

See the sample below and let me know if you could achieve the solution.

<html>
<body>
<script type="text/javascript">
function ShowHelp(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
keychar = String.fromCharCode(keynum);

CHECK HERE if it is the keychar you want and then display the popup. But I think you have to use non-function keys as function keys will
not be trigerring the keypress events

}
</script>

<form>
<input type="text" onkeypress="return ShowHelp(event)" />
</form>

</html>

Re: Key Pressing Events in VB.Net


Dec 05, 2008 03:08 AM | os123

 Here is the simplest code

on HTML

<asp:ScriptManager ID="ScriptManager1" runat="server">


    </asp:ScriptManager>
                 
    <cc1:ModalPopupExtender runat="server" ID="programmaticModalPopup"  BehaviorID="programmaticModalPopup"
                TargetControlID="TextBox1" PopupControlID="P1"
                RepositionMode="RepositionOnWindowScroll">
            </cc1:ModalPopupExtender>
  
            <asp:Panel ID="P1" runat ="server">
            <div id="gr1" style="display:none">
                <asp:GridView ID="GridView1" runat="server">
                </asp:GridView>
                </div>
            </asp:Panel>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

and Code behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


    TextBox1.Attributes.Add("onkeypress", "if(event.which || event.keyCode){if ((event.which == 113) ||(event.keyCode == 113))
{document.getElementById('gr1').setAttribute('style','display:inline');alert('inline');}else{document.getElementById('gr1').setAttribute('style','display:none');alert('none');}}")
    ' Binddata() Code where datagrid binds
    Binddata() 

This site is managed for Microsoft by Neudesic, LLC. | © 2021 Microsoft. All rights reserved.

You might also like