事件Click不会被触发

时间:2017-07-04 12:03:23

标签: asp.net visual-studio

我正试图点击一下点击事件,但是我点击了创建的动态按钮,这不会触发事件,我做了一些断点,这没有显示错误或其他什么,我看到了IE控制台并没有显示错误。

这是<tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>testing</short-name> <uri>/WEB-INF/tld/navbar.tld</uri> <description>This is a demonstration tag library</description> <tag> <name>userInformation</name> <tag-class>tag.NavbarTagHandler</tag-class> <body-content>scriptless</body-content> <description>This tag is for displaying headers of the navbar</description> </tag> 中的代码:

public class NavbarTagHandler extends SimpleTagSupport {

@Override
public void doTag() throws JspException {
    User user = null;
    user = (User) getJspContext().getAttribute("authenticatedUser", PageContext.SESSION_SCOPE);

    JspWriter out = getJspContext().getOut();

    try {
        if (user == null) {
            //not logged
            out.println("Not logged <fmt:message key='message1'/>");
            out.flush();
        } else {
            //logged
            out.println("Logged <fmt:message key='message2'/>");
            out.flush();
        }
    } catch (IOException es) {
        es.printStackTrace();
    }

}

page_load之前我做了这个:

protected void Page_Load(object sender, EventArgs e)
        {
            if (AssignClicked)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showAndHide();", true);

                Button Btn_clic = (Button)sender;
                var name = Btn_clic.Text;

                List.ListUsers listArea = new List.ListUsers();
                List<Data.Area> Area = listArea.AreaList();

                List<Data.Area> ListOfEquiposOk = Area.Where(x => x.AREA == name && x.STANDBY == 0).ToList();

                List<Button> Botones = new List<Button>();

                var TeamFCH = ListOfEquiposOk.Select(x => x.TEAM).Distinct().ToList();

                foreach (var team in TeamFCH)
                {
                    Button newButton = new Button();
                    newButton.CommandName = "Btn" + Convert.ToString(team);
                    newButton.ID = "Btn_" + Convert.ToString(team);
                    newButton.Text = team;
                    newButton.CommandArgument = name;

                    newButton.Click += new System.EventHandler(newButton_Click);

                    newButton.OnClientClick = "return ModalGood();";
                    Botones.Add(newButton);

                    GoodPanel.Controls.Add(newButton);
                    newButton.CssClass = "btn-primary outline separate";
                }
            }    
        }

我在这里点击将Page_load值更改为true:

public bool AssignClicked
        {
            get
            {
                return Convert.ToBoolean(ViewState["AssignClicked"]);
            }
            set
            {
                ViewState["AssignClicked"] = value;
            }
        }

这是创建动态按钮的事件:

AssignClicked

我受这个例子的指导 LinkButton onclick event is not triggering for dynamically created buttons c#

触发事件protected void Assign_Click(object sender, EventArgs e) { AssignClicked = true; Page_Load(sender, e); } 的按钮:

protected void newButton_Click(object sender, EventArgs e)
        {

            Button Btnclick = (Button)sender;
            var team = Btnclick.Text;
            string name = Btnclick.CommandArgument;

            List.ListUsers listArea = new List.ListUsers();
            List<Data.Area> Area = listArea.AreaList();

            List<Data.Area> ListOfToolsOk = Area.Where(x => x.AREA == name && x.TEAM == team && x.STANDBY == 0).ToList();

            var ToolArea = ListOfToolsOk.Select(x => x.TEAM);
            Grv_Eng.DataSource = ListOfToolsOk;
            Grv_Eng.DataBind();
        }

这是动态按钮插入的位置:

Assign_Click

0 个答案:

没有答案