即使我没有单击按钮,我的按钮单击事件也会自动触发。 [英] My button click event fires automatically even if i dont click the button.

查看:112
本文介绍了即使我没有单击按钮,我的按钮单击事件也会自动触发。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在gridview中添加项目。当我点击提交按钮时,它工作正常。但每当我按下文本框中的输入时,它会自动调用按钮事件btnimgnew_Click,我不想要.Below是我的C#代码。任何帮助将赞赏。



I want to add items in my gridview.When i click submit button it works fine.but whenever i press enter in the textbox it calls a button event btnimgnew_Click automatically which i dont want.Below is my C# code.Any help will be appreciated.

protected void btnimgnew_Click(object sender, ImageClickEventArgs e)
    {

        connfordata.Open();
        SqlCommand cmdfrexesp = new SqlCommand("sp_SRXO_InsDocTemplate", connfordata);
        cmdfrexesp.Parameters.AddWithValue("@W113_CompanyID", 5);
        cmdfrexesp.Parameters.AddWithValue("@W113_WebstoreID", 23);
        cmdfrexesp.Parameters.Add("@W113_XMLID", SqlDbType.Int).Direction = ParameterDirection.Output;
        cmdfrexesp.CommandType = CommandType.StoredProcedure;
        cmdfrexesp.ExecuteNonQuery();
        int yourResult = Convert.ToInt32(cmdfrexesp.Parameters["@W113_XMLID"].Value);
        connfordata.Close();
        txtCurrentOrder.Text = yourResult.ToString();
    }

    protected void txtOrderLineNo_TextChanged(object sender, EventArgs e)
    {
        
        Addtogrid(); 
        
    }
public void Addtogrid() 
{
//some code here
}

推荐答案

进入按钮的属性并将UseSubmitBehaviour设置为false。
Go into the properties for your button and set UseSubmitBehaviour to false.


在Enter键时捕获事件很好被按下并相应地进行。看到这个链接



如何禁用asp:ImageButton的提交行为? [ ^ ]



问候..
Its good to catch the event when Enter key is pressed and proceed accordingly. See this link

How to disable submit behaviour of asp:ImageButton?[^]

Regards..


这篇关于即使我没有单击按钮,我的按钮单击事件也会自动触发。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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