I'm currently attempting to create a textbox that triggers a C# function on keydown. To achieve this, I wrote a JavaScript function to initiate a postback event on the keydown of the textbox. However, when setting autopostback=true for the textbox, the C# function would only execute upon clicking outside the box due to autopostback. My goal is to have the C# function execute immediately without needing to click outside the box by utilizing keydown events. Below is the code snippet:
<script language="javascript" type="text/javascript">
function RefreshBox()
{
__doPostBack('<%= SomeTextBox.ClientID%>', '');
}
<asp:TextBox ID="SomeTextBox" runat="server" onkeydown="RefreshQueryBox();"
AutoPostBack="True" ValidationGroup="1"
ontextchanged="AutoText_TextChanged" ViewStateMode="Enabled"></asp:TextBox>
And here's the associated C# code:
protected void AutoText_TextChanged(object sender, EventArgs e)
{
// Implement desired actions here
}
The issue with this implementation is that the entire page refreshes on keydown, preventing the user from typing. Any assistance would be greatly appreciated!
Thank you.