Getting control that fired postback in page_init

后端 未结 1 1927
我寻月下人不归
我寻月下人不归 2021-01-14 01:20

I have a gridview that includes dynamically created dropdownlist. When changing the dropdown values and doing a mass update on the grid (btnUpdate.click), I have to create t

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 01:55

    It is possible to determine which control caused a PostBack by looking at Request.Form["__EVENTTARGET"]. The problem with this is that button ids will not show unless you set their UseSubmitBehavior to false. Here's an example:

    .aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            switch (Request.Form["__EVENTTARGET"].ToString())
            {
                case "ddlOne":
                    break;
                case "btnOne":
                    break;
                case "btnTwo":
                    break;
            }
        }
    }
    

    .aspx

    0 讨论(0)
提交回复
热议问题