<small id='CrF4V'></small><noframes id='CrF4V'>

  • <legend id='CrF4V'><style id='CrF4V'><dir id='CrF4V'><q id='CrF4V'></q></dir></style></legend>

      <bdo id='CrF4V'></bdo><ul id='CrF4V'></ul>
  • <i id='CrF4V'><tr id='CrF4V'><dt id='CrF4V'><q id='CrF4V'><span id='CrF4V'><b id='CrF4V'><form id='CrF4V'><ins id='CrF4V'></ins><ul id='CrF4V'></ul><sub id='CrF4V'></sub></form><legend id='CrF4V'></legend><bdo id='CrF4V'><pre id='CrF4V'><center id='CrF4V'></center></pre></bdo></b><th id='CrF4V'></th></span></q></dt></tr></i><div id='CrF4V'><tfoot id='CrF4V'></tfoot><dl id='CrF4V'><fieldset id='CrF4V'></fieldset></dl></div>
      <tfoot id='CrF4V'></tfoot>

        动态创建的 LinkBut​​tons 的 OnClick 事件不起作用

        时间:2023-06-05

      1. <i id='XV1fK'><tr id='XV1fK'><dt id='XV1fK'><q id='XV1fK'><span id='XV1fK'><b id='XV1fK'><form id='XV1fK'><ins id='XV1fK'></ins><ul id='XV1fK'></ul><sub id='XV1fK'></sub></form><legend id='XV1fK'></legend><bdo id='XV1fK'><pre id='XV1fK'><center id='XV1fK'></center></pre></bdo></b><th id='XV1fK'></th></span></q></dt></tr></i><div id='XV1fK'><tfoot id='XV1fK'></tfoot><dl id='XV1fK'><fieldset id='XV1fK'></fieldset></dl></div>
        <legend id='XV1fK'><style id='XV1fK'><dir id='XV1fK'><q id='XV1fK'></q></dir></style></legend>

            <tbody id='XV1fK'></tbody>

                <tfoot id='XV1fK'></tfoot>
                  <bdo id='XV1fK'></bdo><ul id='XV1fK'></ul>
                • <small id='XV1fK'></small><noframes id='XV1fK'>

                  本文介绍了动态创建的 LinkBut​​tons 的 OnClick 事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我尝试了多种解决方案来解决这个问题,但都没有奏效.基本上,我有一张员工表,用户可以选择通过更新面板动态添加员工.每个员工都被添加为 LinkBut​​ton,此按钮将通过 ajaxToolkit:modalpopupextender 窗口>OnClick 事件,此窗口将显示员工详细信息.问题是当我点击员工姓名时,弹出窗口会显示细节不会.

                  I’ve tried several solutions for this problem but none of them worked. Basically, I have a table of employees and the user have the choice of adding an employee dynamically thru an update panel. Each employee is being added as LinkButton and this button will fire ajaxToolkit:modalpopupextender window through OnClick event, and this window will show the employee details. The problem is when I click on the employee name the popup window will show up BUT the details wont.

                  这是我创建按钮并将其放入表格的代码:

                  Here is the code in which I’m creating the buttons and putting it in the table:

                  LinkButton lbtn = new LinkButton();
                                      lbtn.ID = employee_arry[i] + "_lbtn" + i;
                                      lbtn.Text = employee_arry[i];
                                      lbtn.Click += new EventHandler(this.employee_info);
                                      lbtn.CausesValidation = false;
                                      lbtn.Attributes.Add("runat", "server");
                                      cell.Controls.Add(lbtn);
                  

                  这里是employee_info方法:

                  and here is the employee_info method:

                  //the info will be pulled from the database…
                  public void employee_info(object sender, EventArgs e)
                      { 
                          name.Text = "employee name";
                          dept.Text = "employee department";
                          jobt.Text = "employee job title";
                          email.Text = "employee email";
                          tel.Text = "employee telephone";
                          ModalPopupExtender1.Show();
                      }
                  

                  推荐答案

                  查看这个答案

                  https://stackoverflow.com/a/11127064/1268570

                  这解释了动态控件的行为

                  This explains the behavior of dynamic controls

                  你需要考虑:

                  • 当您不使用母版页时,应在 PreInit 事件中创建动态控件,如果是,则在 Init 事件中创建控件
                  • 避免在这些事件中设置可以在每个帖子中更改的属性,因为当应用视图状态时(在帖子事件中),这些属性将被覆盖
                  • 每次发布​​页面时都必须创建动态控件,避免这种情况 if(!this.IsPostBack) this.CreatemyDynamicControls();
                  • 当您在 PreInit 或 Init 事件中创建控件时,它们的状态将在 post 事件中自动设置,这意味着在 LoadComplete 事件中,即使您在每个 post 中再次创建控件,您的控件也会包含它们的状态,甚至当您没有明确设置它们的状态时.请注意,当您处理在设计时创建的控件时,此行为是不同的,在这种情况下,设置状态的事件是 Load 事件
                  • 事件订阅应该在 PageLoadComplete 之前发生,否则它们将不会被引发

                  如果您还没有找到解决方案,这是一种方法(完整的工作示例):

                  In case you have not found a solution, this is a way to do it (full working example):

                      <asp:ScriptManager runat="server" />
                      <asp:UpdatePanel ID="UpdatePanel1" runat="server" ViewStateMode="Enabled">
                          <ContentTemplate>
                              <asp:Panel runat="server" ID="myPanel">
                              </asp:Panel><br />
                              <asp:Button ID="Button1" Text="add control" runat="server" OnClick="addControl_Click" /><br />
                              <asp:Label ID="lblMessage" runat="server" />
                          </ContentTemplate>
                      </asp:UpdatePanel>
                  

                  代码隐藏

                      protected int NumberOfControls
                      {
                          get
                          {
                              if (ViewState["c"] == null)
                              {
                                  return 0;
                              }
                  
                              return int.Parse(ViewState["c"].ToString());
                          }
                          set
                          {
                              ViewState["c"] = value;
                          }
                      }
                  
                      protected void addControl_Click(object sender, EventArgs e)
                      {
                          this.NumberOfControls++;
                          this.myPanel.Controls.Add(new Literal { Text = "<br />" });
                          this.myPanel.Controls.Add(this.CreateLinkButton(this.NumberOfControls));
                      }
                  
                      protected void Page_PreLoad(object sender, EventArgs e)
                      {
                          this.CreateDynamicLinkButtons();
                      }
                  
                      private void CreateDynamicLinkButtons()
                      {
                          for (int i = 0; i < this.NumberOfControls; i++)
                          {
                              this.myPanel.Controls.Add(new Literal { Text = "<br />" });
                              this.myPanel.Controls.Add(this.CreateLinkButton(i + 1));
                          }
                      }
                  
                      private LinkButton CreateLinkButton(int index)
                      {
                          var l = new LinkButton { Text = "MyLink" + index.ToString(), ID = "myLinkID" + index.ToString() };
                          l.Click += (x, y) =>
                          {
                              this.lblMessage.Text += "<br/>ID: " + (x as LinkButton).ID;
                          };
                  
                          return l;
                      }
                  

                  输出

                  这篇关于动态创建的 LinkBut​​tons 的 OnClick 事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击控件内的文本时,用户控件单击事件不起作 下一篇:从 Javascript 调用代码隐藏

                  相关文章

                  最新文章

                  <tfoot id='IGWLk'></tfoot>
                • <small id='IGWLk'></small><noframes id='IGWLk'>

                    <bdo id='IGWLk'></bdo><ul id='IGWLk'></ul>
                  1. <legend id='IGWLk'><style id='IGWLk'><dir id='IGWLk'><q id='IGWLk'></q></dir></style></legend>

                      <i id='IGWLk'><tr id='IGWLk'><dt id='IGWLk'><q id='IGWLk'><span id='IGWLk'><b id='IGWLk'><form id='IGWLk'><ins id='IGWLk'></ins><ul id='IGWLk'></ul><sub id='IGWLk'></sub></form><legend id='IGWLk'></legend><bdo id='IGWLk'><pre id='IGWLk'><center id='IGWLk'></center></pre></bdo></b><th id='IGWLk'></th></span></q></dt></tr></i><div id='IGWLk'><tfoot id='IGWLk'></tfoot><dl id='IGWLk'><fieldset id='IGWLk'></fieldset></dl></div>