Dotjum 林大鈞's profileDotjum .NET 技巧分享PhotosBlogListsMore Tools Help

Blog


    August 08

    [ASPX] 尋找Page下的Control 透過 foreach 方式

    之前回答於
    http://forums.microsoft.com/msdn-cht/ShowPost.aspx?PostID=765725&SiteID=14

    void ClearTextBoxes()
    {
    foreach(object ctrl in Page.Controls)
    {
     if (ctrl is System.Web.UI.HtmlControls.HtmlForm)
     {
      System.Web.UI.HtmlControls.HtmlForm form = (System.Web.UI.HtmlControls.HtmlForm)ctrl;
      foreach(object subctrl in form.Controls)
      {
       if (subctrl is System.Web.UI.WebControls.TextBox)
       {
        TextBox textctrl = (TextBox)subctrl;
        textctrl.Text = "";
       }
      }
     }
    }
    
    //特別要注意的是 Html 裡面不要設定到 runat="server" 這樣的會尋找範圍
    就要在 System.Web.UI.WebControls.Table 下
    剛好今天COPY另一個Html table 過來沒有注意到多弄了這段。
     <table background="ballot_bk1.GIF" border="0" runat="server"
                cellpadding="0" cellspacing="0" style="width: 500px; height: 600px">

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Mar. 27

    Trackbacks

    The trackback URL for this entry is:
    http://dotjum.spaces.live.com/blog/cns!F0C7688CEBFA8680!250.trak
    Weblogs that reference this entry
    • None