admin管理员组文章数量:1406152
KeyPress
or KeyDown
events aren't available in System.Web.UI.WebControls.TextBox
so one way to do it is using Java-Scripts, but want to fire some Sql queries at these events. is it possible to execute Sql queries from JavaScript? if not then how do I do it?
KeyPress
or KeyDown
events aren't available in System.Web.UI.WebControls.TextBox
so one way to do it is using Java-Scripts, but want to fire some Sql queries at these events. is it possible to execute Sql queries from JavaScript? if not then how do I do it?
- 1 To fire events the page has to be posted and I'm sure you don't want that for every keypress. Would ajax be suitable for this? – tom502 Commented Jun 21, 2011 at 14:39
- 1 I haven't ever used ajax yet, but i guess i can learn it for this. – love Computer science Commented Jun 21, 2011 at 14:41
3 Answers
Reset to default 5No, You cannot execute SQL from javascript. Your best bet is to use something like jquery and wire up an event to .change() (or something simiiar) and then make an ajax request to perform the sql query. A server side event (which doesn't exist) for textbox key press or key down would submit the page everytime and that just wouldn't work for the user. You might look into jquery ui autoplete if you're looking to display some information
If you need to capture key events, you'll need to use Javascript.
You can use ajax to then send these keys to the server and perform actions.
My guess is that you're thinking of something along the lines of Google Suggest.
You can handle the key press event in the given way
But you can't fire SQL queries in these events.
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label1.Text = "Start";
}
TextBox1.Attributes.Add("onkeyup", "rewriteLabel()");
}
</script>
<script type="text/javascript">
function rewriteLabel()
{
TextBox1.Text = Label1.text;
}
</script>
<html xmlns="http://www.w3/1999/xhtml" >
<head >
<title >test</title>
</head>
<body>
<form id="form1" runat="server">
<br />
<asp:TextBox ID="TextBox1" runat="server" /><br />
<asp:Label ID="Label1" Runat="server" BorderWidth="1px" />
</form>
</body>
</html>
本文标签: chow do I handle KeyPress or KeyDown events in aspnetStack Overflow
版权声明:本文标题:c# - how do I handle KeyPress or KeyDown events in asp.net? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744974283a2635422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论