find control in page

后端 未结 9 1060
孤城傲影
孤城傲影 2020-12-11 02:37

HTML


    
相关标签:
9条回答
  • 2020-12-11 03:40

    To find the master page control on the other pages we can use this:

    Button btnphotograph = (Button)this.Master.FindControl("btnphotograph");
    btnphotograph.Text="Hello!!";
    
    0 讨论(0)
  • 2020-12-11 03:40

    This should find any Control on page

    private Control FindALL(ControlCollection page, string id)
    {
      foreach (Control c in page)
      {
        if (c.ID == id)
        {
          return c;
        }
    
        if (c.HasControls())
        {
          var res = FindALL(c.Controls, id);
    
          if (res != null)
          {
            return res;
          }
        }     
      }
      return null;
    }
    

    Call like:

    Button btn = (Button)FindALL(this.Page.Controls, "a");
    btn.Text = "whatever";
    
    0 讨论(0)
  • 2020-12-11 03:41

    See if the ID of the control is in fact being rendered as 'a'. Use firebug or developer tools while page is loading. You can change client id mode to static and get the same ID each time.

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