Issue in modalpopupextender when clicking enter key in textbox Or Trigger a Button Click with JavaScript on the Enter key in a TextBox
<%@ Register Assembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Issue in modalpopupextender when clicking enter key in textbox Or Trigger a Button
Click with JavaScript on the Enter key in a TextBox</title>
<script language="javascript" type="text/javascript">
function btnclick() {
alert("Hi");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ajax:ModalPopupExtender ID="ModalRecipients"BehaviorID="ModalRecipients" runat="server"
PopupControlID="pnlRecipients" DropShadow="true"
TargetControlID="btnMain"BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<div style="overflow: auto;">
<asp:Panel ID="pnlRecipients" runat="server" Width="550px"Style="background-color: White;
display: none">
<asp:TextBox runat="server" ID="txt" onkeydown="if (event.keyCode == 13) document.getElementById('btn').click()" />
<asp:Button runat="server" ID="btn" OnClick="btn_Click"Text="button" />
</asp:Panel>
<asp:Button runat="server" ID="btnMain"OnClick="btnMain_Click" Text="MainPage Button" UseSubmitBehavior="false" />
</div>
</div>
</form>
</body>
</html>
|
C#:
using System.Globalization;
public partial class EnterKeyCheck : System.Web.UI.Page
{
protected void btn_Click(object sender, EventArgs e)
{
Response.Write(txtData.Text );
}
protected void btnMain_Click(object sender, EventArgs e)
{
ModalRecipients.Show();
}
}
|
VB.NET:
Imports System.Globalization
Partial Public Class EnterKeyCheck
Inherits System.Web.UI.Page
Protected Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Write(txtData.Text )
End Sub
Protected Sub btnMain_Click(ByVal sender As Object, ByVal e As EventArgs)
ModalRecipients.Show()
End Sub
End Class
|
Output: