ASP .NET Button event handlers do not fire on the first click, but on the second click after a PostBack

后端 未结 8 2061
Happy的楠姐
Happy的楠姐 2020-12-02 17:02

Background: I am customizing an existing ASP .NET / C# application. It has it\'s own little \"framework\" and conventions for developers to follow when exte

8条回答
  •  被撕碎了的回忆
    2020-12-02 17:44

    A quick fix is to set an ID to the ASCX control your are loading on a page. For example, if your code is like this:

            UserControl SpecsControl = (UserControl)Page.LoadControl("../name.ascx");
            SpecsContainer.Controls.Add(SpecsControl);
    

    then you need to add a line (before Controls.Add):

                SpecsControl.ID = "Aribtrary_Name";
    

    Then your handler method is fired at the first click.

提交回复
热议问题