<bdo id='eq88j'></bdo><ul id='eq88j'></ul>
  • <legend id='eq88j'><style id='eq88j'><dir id='eq88j'><q id='eq88j'></q></dir></style></legend>
  • <small id='eq88j'></small><noframes id='eq88j'>

    <tfoot id='eq88j'></tfoot>

      <i id='eq88j'><tr id='eq88j'><dt id='eq88j'><q id='eq88j'><span id='eq88j'><b id='eq88j'><form id='eq88j'><ins id='eq88j'></ins><ul id='eq88j'></ul><sub id='eq88j'></sub></form><legend id='eq88j'></legend><bdo id='eq88j'><pre id='eq88j'><center id='eq88j'></center></pre></bdo></b><th id='eq88j'></th></span></q></dt></tr></i><div id='eq88j'><tfoot id='eq88j'></tfoot><dl id='eq88j'><fieldset id='eq88j'></fieldset></dl></div>
      1. 动态创建的链接按钮列表,链接按钮不回发

        时间:2023-09-16
          <tbody id='sIT9h'></tbody>

            <legend id='sIT9h'><style id='sIT9h'><dir id='sIT9h'><q id='sIT9h'></q></dir></style></legend>
            <tfoot id='sIT9h'></tfoot>
                <bdo id='sIT9h'></bdo><ul id='sIT9h'></ul>

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

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

                  本文介绍了动态创建的链接按钮列表,链接按钮不回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您好,我正在ul li"列表中动态创建链接按钮.然后我试图将每个链接按钮绑定到一个单击事件,在该事件中我为单击的链接按钮的文本设置一个标签.但是应该触发的事件没有被触发?

                  Hi I am dynamically creating link buttons in a 'ul li' list. I am then trying to tie each link button to a click event where i set a label to the text of the link button clicked. however the event that should fire doesnt get fired?

                      if (!Page.IsPostBack)
                          {
                  int listItemIds = 0;
                         foreach (Node productcolour in product.Children)
                         {
                             HtmlGenericControl li = new HtmlGenericControl("li");
                             LinkButton lnk = new LinkButton();
                             lnk.ID = "lnk" + listItemIds;
                             lnk.Text = productcolour.Name;
                             lnk.Click += new EventHandler(Clicked);
                             //lnk.Command += new CommandEventHandler(lnkColourAlternative_Click);
                             //lnk.Click 
                             li.Controls.Add(lnk);
                             ul1.Controls.Add(li);
                             listItemIds++;
                         }
                  }
                  

                  上面的内容包含在 if(!page.ispostback) 中,并且标签文本永远不会在其他任何地方设置.活动结束

                  the above is wrapped within a if(!page.ispostback) and the label text is never set anywhere else. heres to the event

                  protected void Clicked(object sender, EventArgs e)
                  {
                      LinkButton lno = sender as LinkButton;
                      litSelectedColour.Text = lno.Text;
                  
                  }
                  

                  推荐答案

                  代码必须在每次回发时运行:

                  Code must run on each postback:

                      protected override void OnInit(EventArgs e)
                      {
                          base.OnInit(e);
                  
                          int listItemIds = 1;
                  
                          for (int i = 0; i < 10; i++)
                          {
                              var li = new HtmlGenericControl("li");
                              var lnk = new LinkButton();
                  
                              lnk.ID = "lnk" + listItemIds;
                              lnk.Text = "text" + i;
                              lnk.Click += Clicked;
                              //lnk.Command += new CommandEventHandler(lnkColourAlternative_Click);
                              //lnk.Click 
                              li.Controls.Add(lnk);
                              ul1.Controls.Add(li);
                              listItemIds++;
                          }
                      }
                  
                      private void Clicked(object sender, EventArgs e)
                      {
                          var btn = sender as LinkButton;
                          btn.Text = "Clicked";
                      }
                  

                  这篇关于动态创建的链接按钮列表,链接按钮不回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用反射将事件处理程序附加到事件? 下一篇:c# 使用事件处理程序WorkbookOpen

                  相关文章

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

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