简体   繁体   English

在Asp.Net中使用Keyup事件调用服务器端功能

[英]Call Server Side function with Keyup Event in Asp.Net

I have a TextBox and I want to capture the Keyup in the Textbox and get the TextBox value at the Code Behind File and Bind The GridView with the Input Received from the TextBox. 我有一个TextBox,我想在Textbox中捕获Keyup ,并在文件后面的代码中获取TextBox的值,然后将GridView与从TextBox接收的输入绑定。

I don't want to use Text_Change Event of Asp.net. 我不想使用Asp.net的Text_Change事件。 i want that when ever user enter anything in the TextBox, that value should go to code behind and bind the grid by calling BindGrid Function 我希望当用户在TextBox中输入任何内容时,该值应转到代码后面并通过调用BindGrid函数绑定网格

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

protected void BindGrid(string searchvalue)
{    
    //  i want the txtSearch value over here.    
}

You need to use asp.net ajax. 您需要使用asp.net ajax。 Putting your button and grid in UpdatePanel will update the gridview after binding on button click. 将按钮和网格放在UpdatePanel中后,单击按钮绑定后,将更新gridview。

In html 在html中

<asp:UpdatePanel runat="server" ID="updatePanel">
<asp:TextBox runat="server" ID="search"  
                ClientIDMode="Static" OnKeyUp="refreshPanel(this);" />

In javascript 在JavaScript中

function refreshPanel(textbox) {
     alert(this.value)
    __doPostBack('<%= updatePanel.UniqueID %>', this.value);
}

In code behind 在后面的代码中

 string parameter = Request["__EVENTARGUMENT"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM