Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Walk all controls on a page [modified]

Walk all controls on a page [modified]

Scheduled Pinned Locked Moved ASP.NET
databasedesigndebugginghelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    I've created a literal for each of my text snippets (blah blah blah). I have other literals that are updated based on code execution, so that is the reason all literals start with ABCD. In Page_Load, I do something like: string pageName = "UniqueName"; languageCode = 1; // Maps to English in database // Global to page TranslateControls(pageName, this.Controls); I then define the TranslateControls method as: private void TranslateControls(string pageName, ControlCollection controls) { for (int i=0; i < controls.Count; i++) { Control ctrl = controls[i]; if (ctrl.HasControls()) { // logger.Trace("Control: {0} has {1} child controls.", ctrl.UniqueID, ctrl.Controls.Count); TranslateControls(pageName, ctrl.Controls); } else { if (ctrl.GetType() == typeof(System.Web.UI.WebControls.Literal)) { // check name if (ctrl.UniqueID.StartsWith("ABCD")) { // Replace with database lookup Literal litTemp = (Literal)ctrl; Database db = new Database(); string textTranslation = db.GetText(pageName, ctrl.UniqueID, languageCode); litTemp.Text = textTranslation; } } } } } Problem is, some controls are ignored -- when logging/stepping through, it appears that they are not part of the ControlCollection. Any thoughts/ideas? -- modification When page is initially loaded, all controls are displayed properly. However, on postback, some controls are missed and appear blank (odd, as they have initial text, and the db.GetText method returns either valid text or ctrl.UniqueID surrounded by underscores). -- end modification Thanks, Glenn -- modified at 16:07 Wednesday 25th April, 2007

    X G 2 Replies Last reply
    0
    • G Glenn E Lanier II

      I've created a literal for each of my text snippets (blah blah blah). I have other literals that are updated based on code execution, so that is the reason all literals start with ABCD. In Page_Load, I do something like: string pageName = "UniqueName"; languageCode = 1; // Maps to English in database // Global to page TranslateControls(pageName, this.Controls); I then define the TranslateControls method as: private void TranslateControls(string pageName, ControlCollection controls) { for (int i=0; i < controls.Count; i++) { Control ctrl = controls[i]; if (ctrl.HasControls()) { // logger.Trace("Control: {0} has {1} child controls.", ctrl.UniqueID, ctrl.Controls.Count); TranslateControls(pageName, ctrl.Controls); } else { if (ctrl.GetType() == typeof(System.Web.UI.WebControls.Literal)) { // check name if (ctrl.UniqueID.StartsWith("ABCD")) { // Replace with database lookup Literal litTemp = (Literal)ctrl; Database db = new Database(); string textTranslation = db.GetText(pageName, ctrl.UniqueID, languageCode); litTemp.Text = textTranslation; } } } } } Problem is, some controls are ignored -- when logging/stepping through, it appears that they are not part of the ControlCollection. Any thoughts/ideas? -- modification When page is initially loaded, all controls are displayed properly. However, on postback, some controls are missed and appear blank (odd, as they have initial text, and the db.GetText method returns either valid text or ctrl.UniqueID surrounded by underscores). -- end modification Thanks, Glenn -- modified at 16:07 Wednesday 25th April, 2007

      X Offline
      X Offline
      xibeifeijian
      wrote on last edited by
      #2

      Delete else please.This is a logical error.

      :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

      G 1 Reply Last reply
      0
      • X xibeifeijian

        Delete else please.This is a logical error.

        :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

        G Offline
        G Offline
        Glenn E Lanier II
        wrote on last edited by
        #3

        Even with the else removed, the literals do not appear.

        1 Reply Last reply
        0
        • G Glenn E Lanier II

          I've created a literal for each of my text snippets (blah blah blah). I have other literals that are updated based on code execution, so that is the reason all literals start with ABCD. In Page_Load, I do something like: string pageName = "UniqueName"; languageCode = 1; // Maps to English in database // Global to page TranslateControls(pageName, this.Controls); I then define the TranslateControls method as: private void TranslateControls(string pageName, ControlCollection controls) { for (int i=0; i < controls.Count; i++) { Control ctrl = controls[i]; if (ctrl.HasControls()) { // logger.Trace("Control: {0} has {1} child controls.", ctrl.UniqueID, ctrl.Controls.Count); TranslateControls(pageName, ctrl.Controls); } else { if (ctrl.GetType() == typeof(System.Web.UI.WebControls.Literal)) { // check name if (ctrl.UniqueID.StartsWith("ABCD")) { // Replace with database lookup Literal litTemp = (Literal)ctrl; Database db = new Database(); string textTranslation = db.GetText(pageName, ctrl.UniqueID, languageCode); litTemp.Text = textTranslation; } } } } } Problem is, some controls are ignored -- when logging/stepping through, it appears that they are not part of the ControlCollection. Any thoughts/ideas? -- modification When page is initially loaded, all controls are displayed properly. However, on postback, some controls are missed and appear blank (odd, as they have initial text, and the db.GetText method returns either valid text or ctrl.UniqueID surrounded by underscores). -- end modification Thanks, Glenn -- modified at 16:07 Wednesday 25th April, 2007

          G Offline
          G Offline
          Glenn E Lanier II
          wrote on last edited by
          #4

          Glenn E. Lanier II wrote:

          When page is initially loaded, all controls are displayed properly. However, on postback, some controls are missed and appear blank (odd, as they have initial text, and the db.GetText method returns either valid text or ctrl.UniqueID surrounded by underscores).

          Knowing this bit had something to do with it, after much head-banging/debugging, I realized that my literal was not listed in the .cs file. My non-required fields displayed, as they are defined: <label for="txtBillFirstName"><asp:label id="lblBillFirstName" runat="server"><asp:literal runat="server" id="litTextBillNameFirst">First Name:</asp:literal></asp:label></label> but the [initially] required fields were not, defined as: <label for="txtBillFirstName"><asp:label id="lblBillFirstName" runat="server">* <asp:literal runat="server" id="litTextBillNameFirst">First Name:</asp:literal></asp:label></label> Apparently, you can have an asp:literal in an asp:label if it is the only thing in the label, but mixing text with a literal doesn't appear to work. The initial text displayed on the page load, but not on a postback - not sure why even the * didn't show up. Some of the fields are only required based on selections made on the form, so if I cause the error conditions, those labels displayed as required, which threw me off track a little. --G -- modified at 12:41 Thursday 26th April, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups