做一个数据库查询的文本框onblur事件 [英] Do a database query on Textbox onblur event

查看:125
本文介绍了做一个数据库查询的文本框onblur事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net 3.5使用C#。我需要当用户输入txtProductID产品ID做一个数据库查询。我想这样做JavaScript是出了问题,因为这将是服务器端调用。
我在网页的Page_Load事件写了这个代码:

I am using asp.net 3.5 with C#. I need to do a database lookup when a user enters ProductID in txtProductID. I guess doing javascript is out of the question since this will have to be server side call. I wrote this code in the page_load event of the webpage:

        protected void Page_Load(object sender, EventArgs e)
    {
        txtProductID.Attributes.Add("onblur", "LookupProduct()");
    }

        protected void LookupProduct()
    {
        //Lookup Product information on onBlur event;
    }



我收到一条错误消息:Microsoft JScript运行时错误:预期的对象
口如何解决此问题?

I get an error message: Microsoft JScript runtime error: Object expected How can I resolve this ?

推荐答案

使用的 TextBox.TextChanged 事件。

ASPX标记:

<asp:TextBox ID="txtProductID" runat="server" AutoPostBack="true" OnTextChanged="txtProductID_TextChanged" />



代码隐藏:

Codebehind:

protected void txtProductID_TextChanged(object sender, EventArgs e)
{
   // do your database query here
}

这篇关于做一个数据库查询的文本框onblur事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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