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. Adding controls at client side

Adding controls at client side

Scheduled Pinned Locked Moved ASP.NET
question
6 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.
  • S Offline
    S Offline
    Syed Abdul Khader
    wrote on last edited by
    #1

    Is there any way to add controls dynamically at client side without any postback?

    M 1 Reply Last reply
    0
    • S Syed Abdul Khader

      Is there any way to add controls dynamically at client side without any postback?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You may reconsider your approach here as a web server control basically exists at the server side, and at the client side what you see is the static html markup rendered from the control. So you are only able to do that with the server side code, however, you can provide some client side script to add a html element dynamically. For example:

      function AddDynamicCheckBox()
      {
      var chkBox = document.createElement("<INPUT style='display:inline' type=checkbox tabindex=-1 type=checkbox/>");
      window.Form1.appendChild(chkBox);
      }

      S 2 Replies Last reply
      0
      • M minhpc_bk

        Hi there, You may reconsider your approach here as a web server control basically exists at the server side, and at the client side what you see is the static html markup rendered from the control. So you are only able to do that with the server side code, however, you can provide some client side script to add a html element dynamically. For example:

        function AddDynamicCheckBox()
        {
        var chkBox = document.createElement("<INPUT style='display:inline' type=checkbox tabindex=-1 type=checkbox/>");
        window.Form1.appendChild(chkBox);
        }

        S Offline
        S Offline
        Syed Abdul Khader
        wrote on last edited by
        #3

        Thanks for your answer. I can add now the controls dynamically at client side and access the values of the added controls at the server side.

        1 Reply Last reply
        0
        • M minhpc_bk

          Hi there, You may reconsider your approach here as a web server control basically exists at the server side, and at the client side what you see is the static html markup rendered from the control. So you are only able to do that with the server side code, however, you can provide some client side script to add a html element dynamically. For example:

          function AddDynamicCheckBox()
          {
          var chkBox = document.createElement("<INPUT style='display:inline' type=checkbox tabindex=-1 type=checkbox/>");
          window.Form1.appendChild(chkBox);
          }

          S Offline
          S Offline
          Syed Abdul Khader
          wrote on last edited by
          #4

          Hi minhpc_bk, Everything is working fine. The problem what I have now is the control added through client side script disappears when the page is refreshed. Can we prevent this?

          M 1 Reply Last reply
          0
          • S Syed Abdul Khader

            Hi minhpc_bk, Everything is working fine. The problem what I have now is the control added through client side script disappears when the page is refreshed. Can we prevent this?

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Unfortunately no, because when you hit Refresh, a http request will be posted gain and you only see the result markup returned from the server, of course it does not contain any html element dynamically added at the previous step. You may think of persisting the dynamically generated markup by calling web services at the client side, it certainly requires you to provide more code. It should work in the way that every time the page is loaded, your client side script will invoke a web method to pull out the dynamically added markup and attach to the document, also you need to save any added element by the user for loading later when the user hit Refresh. For the sample code of working with web service in client side script, you can see this blog entry: http://weblogs.asp.net/mschwarz/archive/2004/07/16/184748.aspx[^] Or you may need a work-around solution here. Just some ideas.

            S 1 Reply Last reply
            0
            • M minhpc_bk

              Unfortunately no, because when you hit Refresh, a http request will be posted gain and you only see the result markup returned from the server, of course it does not contain any html element dynamically added at the previous step. You may think of persisting the dynamically generated markup by calling web services at the client side, it certainly requires you to provide more code. It should work in the way that every time the page is loaded, your client side script will invoke a web method to pull out the dynamically added markup and attach to the document, also you need to save any added element by the user for loading later when the user hit Refresh. For the sample code of working with web service in client side script, you can see this blog entry: http://weblogs.asp.net/mschwarz/archive/2004/07/16/184748.aspx[^] Or you may need a work-around solution here. Just some ideas.

              S Offline
              S Offline
              Syed Abdul Khader
              wrote on last edited by
              #6

              Ok, thanks for your answer. I have little time to finish the work and hence I cannot go for the web service solution. So I want to leave the refresh problem as it is now. Now what I am doing is reading the values of dynamically added controls from the page and creating server side controls to show them again after a form submit. In the client side control creation, I am appending a br tag to bring the generated control to the next line. I cannot replicate the same br after a form submit. When I use a HtmlGenericControl to produce the br, it generates

              . So I am getting an intermediate line between two controls during the re-creation. Is there any way to solve this?

              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