What are different ways to implement behaviour on click even

本文关键字:behaviour on click even implement to are different ways What | 更新日期: 2023-09-27 18:07:20

我在ASP中"继承"了一个项目。NET,我确信某个存储过程与按下一个名为button_Search的按钮有关(我也用SQL Server探查器确认了这一点(。但是,与点击按钮相关的方法是空的:

protected void button_Search_Click(object sender, EventArgs e)
    {
    }

在ASP中,这种行为(运行返回选择的存储过程,然后将其绑定到网格视图(还能在哪里实现。NET,如果不在按钮中_Search_Click?提前谢谢。

What are different ways to implement behaviour on click even

 protected void Page_Load(object sender, EventArgs e){
     if (IsPostBack){ //confirms it's a PostBack and not initial load
        Button myButton = (Button)(sender as Page).FindControl("button_Search"); //find your button
        if (myButton.ID == "button_Search"){
            // your normal code (the code you intend in button_Search_Click )goes here...
        }
     }
 }

根据项目结构,可以是任意数量的方法/函数。

aspx页面是否包含类似以下代码的内容?

 <asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="JavacriptClick()" OnClick="Button1_Click" />

OnClick函数将在代码绑定文件中指定一个方法。OnClientClick将是一个javascript函数,这意味着一个ajax调用。

如果以上都不存在,则可以使用搜索按钮来触发回发,并且逻辑位于页面生命周期中的某个位置。在if IsPostback语句中的PageLoad方法中找到一些逻辑并不罕见。

关于激活/填充gridview的存储过程,请检查gridview是否具有SqlDataSource/ObjectDataSource更多信息,请访问https://msdn.microsoft.com/en-us/library/aa479341.aspx了解更多详细信息。

protected void Page_Load(object sender, EventArgs e){
  //Please check for below line code
  this.button_Search.clicked += CallStoredProc;
 }
protected void CallStoredProc(object sender, EventArgs e){
// Here the SP could be called
}

请查看此类代码