How to check whether ASP.NET button is clicked or not on page load

前端 未结 5 834
不思量自难忘°
不思量自难忘° 2020-12-29 00:12

How can I check whether a particular button was clicked or not in ASP.NET?

I think I need to perform some operation on Page_Load. This shouldn\'t be ent

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 00:56

    I just got the same trouble, have to do some logic judgement in the Page_Load method to treat different event(which button was clicked). I realize the arm to get the as the following example. The front end aspx source code(I have many Buttons with IDs F2, F3, F6, F12.

    The back end aspx.cs source code, what I need to do is judge which button was clicked when Page_Load was triggered. It seems a little stupid, but works. In your situation, the button be clicked will be added into dic. I hope that will be helpful to some one.

    Dictionary dic = new Dictionary();
    foreach(var id in new string[]{"F2","F3","F6","F12"})
    {
           foreach (var key in Request.Params.AllKeys)
                        {
                            if (key != null && key.ToString().Contains(id))
                                dic.Add(id, Request[key.ToString()].ToString()); 
                        }
    }
    

提交回复
热议问题