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. JavaScript
  4. postback issue when using dynamically created datetimepicker using javascript

postback issue when using dynamically created datetimepicker using javascript

Scheduled Pinned Locked Moved JavaScript
javascripthelphtmldesigntools
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.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    Hi, I am using dynamic datetimepicker that the user can add to any number. But I am having postback problem. Once I submit it, the return page should have all the submitted values including those added dynamic datetimepicker. Right now when i submit and when the page returns, all other static controls with data are there but no dynamically added datetimepicker controls. Below is the code I used to add datatimepicker dynamically using javascript:

    <html>

    <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="jquery-ui.min.js"></script>
    <script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>
    <script type="text/javascript" src="jquery-ui-sliderAccess.js"></script>
    <script type="text/javascript">
    $(function () {

         var counter = 1;
          jQuery("#<%= btnD1Add.ClientID %>").click(function (event) {
            event.preventDefault(); //this code is added to prevent the default submit functionality of the button
    
            jQuery("*   ").appendTo(".Date1More");
                jQuery("<label id='lblD1StartTime" + counter + "'>StartTime:</label><input type='text' id='txtD1StartTime"  +counter + "' name='txtStartTime1'/>").timepicker({
                    hourGrid: 10,
                    minuteGrid: 10,
                    timeFormat: 'hh:mm tt'
                }).appendTo(".Date1More");
                
                counter++;
            });
        });
    </script>
    

    </html>

    Now how to use postback for these controls? I had tried to use following code in code but didn't work. I even tried it using !Ispostback() function under pageLoad but no effect.

    protected string[] txtStartTime1;
    protected void Page_Load(object sender, EventArgs e)
    {

            txtStartTime1 = Request.Form.GetValues("txtStartTime1");
        }
    

    protected void Page_Init(object sender, EventArgs e)
    {

    A 1 Reply Last reply
    0
    • D Dhyanga

      Hi, I am using dynamic datetimepicker that the user can add to any number. But I am having postback problem. Once I submit it, the return page should have all the submitted values including those added dynamic datetimepicker. Right now when i submit and when the page returns, all other static controls with data are there but no dynamically added datetimepicker controls. Below is the code I used to add datatimepicker dynamically using javascript:

      <html>

      <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
      <script type="text/javascript" src="jquery-ui.min.js"></script>
      <script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>
      <script type="text/javascript" src="jquery-ui-sliderAccess.js"></script>
      <script type="text/javascript">
      $(function () {

           var counter = 1;
            jQuery("#<%= btnD1Add.ClientID %>").click(function (event) {
              event.preventDefault(); //this code is added to prevent the default submit functionality of the button
      
              jQuery("*   ").appendTo(".Date1More");
                  jQuery("<label id='lblD1StartTime" + counter + "'>StartTime:</label><input type='text' id='txtD1StartTime"  +counter + "' name='txtStartTime1'/>").timepicker({
                      hourGrid: 10,
                      minuteGrid: 10,
                      timeFormat: 'hh:mm tt'
                  }).appendTo(".Date1More");
                  
                  counter++;
              });
          });
      </script>
      

      </html>

      Now how to use postback for these controls? I had tried to use following code in code but didn't work. I even tried it using !Ispostback() function under pageLoad but no effect.

      protected string[] txtStartTime1;
      protected void Page_Load(object sender, EventArgs e)
      {

              txtStartTime1 = Request.Form.GetValues("txtStartTime1");
          }
      

      protected void Page_Init(object sender, EventArgs e)
      {

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      To understand this behaviour you need to understand page life-cycle properly. I can't explain the whole stuffs here but would recommend you to read it.

      Dhyanga wrote:

      Is there any another way to do it?

      Yes, you can very well avoid postback by using ajax or PageMethods. Just see which is best suited in your scenario.

      Life is a computer program and everyone is the programmer of his own life.

      D 1 Reply Last reply
      0
      • A Anurag Gandhi

        To understand this behaviour you need to understand page life-cycle properly. I can't explain the whole stuffs here but would recommend you to read it.

        Dhyanga wrote:

        Is there any another way to do it?

        Yes, you can very well avoid postback by using ajax or PageMethods. Just see which is best suited in your scenario.

        Life is a computer program and everyone is the programmer of his own life.

        D Offline
        D Offline
        Dhyanga
        wrote on last edited by
        #3

        Thank you very much Anurag. I don't know why I didn't think of using Ajax before I spent lots of time thinking on this. :)

        Dhyanga

        A 1 Reply Last reply
        0
        • D Dhyanga

          Thank you very much Anurag. I don't know why I didn't think of using Ajax before I spent lots of time thinking on this. :)

          Dhyanga

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          You are welcome. :)

          Life is a computer program and everyone is the programmer of his own life.

          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