处理在asp.net中输入按键事件

时间:2015-07-31 06:57:03

标签: c# asp.net c#-4.0

我在按钮点击下面写了下面的代码行

$or

现在我希望每当用户按下回车键时,它应该执行与上述代码中的try块相同的操作。请帮我解决如何处理asp.net c#中的回车键事件?

2 个答案:

答案 0 :(得分:1)

在asp:Panel中包围控件并添加DefaultButton属性

table:
product_base
primary:
product_id
column:
product_id SERIAL NOT NULL,
name varchar,
introduction varchar,
description varchar,
size_name varchar,
size_description varchar,
active bit NOT NULL,
create_by_user_id integer,
create_date timestamp,
modified_by_user_id integer,
modified_date timestamp


table:
product_color
primary:
product_color_id
column:
product_color_id SERIAL NOT NULL,
product_id integer NOT NULL, FOREIGN KEY (product_id) REFERENCES product_base (product_id) ON DELETE CASCADE
color_rgb_code_r integer,
color_rgb_code_g integer,
color_rgb_code_b integer,
color_name varchar,
active bit NOT NULL,
create_by_user_id integer,
create_date timestamp,
modified_by_user_id integer,
modified_date timestamp


table:
product_color_price
primary:
product_color_price_id
column:
product_color_price_id SERIAL NOT NULL,
product_color_id integer NOT NULL, FOREIGN KEY (product_color_id) REFERENCES product_color (product_color_id) ON DELETE CASCADE
price integer,
create_by_user_id integer,
create_date timestamp,
modified_by_user_id integer,
modified_date timestamp


table:
product_color_quantity
primary:
product_color_quantity_id
column:
product_color_quantity_id SERIAL NOT NULL,
product_color_id integer NOT NULL, FOREIGN KEY (product_color_id) REFERENCES product_color (product_color_id) ON DELETE CASCADE
quantity integer,
create_by_user_id integer,
create_date timestamp,
modified_by_user_id integer,
modified_date timestamp

只要该面板中的一个控件具有焦点,您可以按Enter键执行按钮单击

答案 1 :(得分:0)

<强> ASPX:

<asp:TextBox ID="TextBox1" clientidmode="Static" runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox>    
<asp:Button ID="Button1" runat="server" style="display:none" Text="Button" />

<强> JS:

function EnterEvent(e) {
        if (e.keyCode == 13) {
            __doPostBack('<%=Button1.UniqueID%>', "");
        }
    }

<强> CS:

 protected void btnGo_Click(object sender, EventArgs e)
{
    try
    {
        SearchHint = txtName.Text.Split('[')[0].ToString().Trim();
        WebUtility.SetCookie(Response, "gslCountry", WebUtility.GetDropDownListValue(ddlCountry, String.Empty), false);
        WebUtility.SetCookie(Response, "gslState", WebUtility.GetDropDownListValue(ddlState, String.Empty), false);
        WebUtility.SetCookie(Response, "gslName", txtName.Text, false);
        WebUtility.SetCookie(Response, "gslCity", txtCity.Text, false);
        BindGrid();
    }
    catch (Exception ex)
    {

    }
}