如何在文本框的keyup事件上调用c#方法. [英] how to call a c# method on keyup event of textbox.

查看:86
本文介绍了如何在文本框的keyup事件上调用c#方法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_Load(object sender, EventArgs e)
    {
TextBox1.Attributes.Add("onkeyup", "fillsort();");
}

 protected void fillsort()
    {
        DataList1.DataSource = ob.dataset("select * from Course where course_title like '" + TextBox1.Text + "%'");
        DataList1.DataBind();
    }



问题是这样,在keyup上什么也没发生..我的意思是fillsort()没有被调用! 为什么?



problem is this, on keyup nothing happens.. i mean fillsort() not called!!
why??

推荐答案

我建​​议在客户端使用onkeyup并向服务器端进行AJAX调用

如果需要服务器端,请使用OnTextChanged
I would suggest onkeyup to be used on client side and make an AJAX call to the server side

If you need server side then use OnTextChanged
<asp:TextBox ID='Textbox1' runat='server' OnTextChanged=' fillsort'>
    </asp:TextBox>
public void fillsort(Object sender, EventArgs e)
{
//your code
}




我们无法直接从javascript调用服务器方法.

仅当该方法是pagemethod时才有可能.但是在这种情况下,存在一个问题,即当您调用服务器方法仅用于在服务器端执行某些处理时,这些数据到数据列表无效.

我们可以通过使用Jquery
做到这一点
Hi,

We cannot call server methods directly from javascript.

It can possible only when that method is pagemethod.But here there is a problem in this situation those data to datalists are not effect while you calling server method its just used for to do some process in server side.

We can do this by using Jquery

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script language ="javascript" >
       function f1() {


.get(" default22.aspx?action = getval",{val1:
.get("default22.aspx?action=getval", { val1:


这篇关于如何在文本框的keyup事件上调用c#方法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆