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. ASPX How to get the form initiated from OperatePage - actually should be the existing instance

ASPX How to get the form initiated from OperatePage - actually should be the existing instance

Scheduled Pinned Locked Moved ASP.NET
questioncsharptutorialannouncement
13 Posts 3 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.
  • Q QuickBooksDev

    I have a simple VB.Net web app that gets a large table based on Form controls and I need it display the progress such as Doing 'Record# nnn'. This method can be simulated with via clicking on a button the the form is initiated which is the instance that we need to access. lblMsg is a label on the form what I would like to update.

    Public Function GetTable
    Dim I as Integer
    for I = 1 to 10
    lblMsg.Text = "Doing Record# " & i
    Sleep 1000
    next
    End Function

    We are currently trying the below but when GetTable gets control lblMsg is nothing which means that the form is not initialed. How can I get this to work?

    $(document).ready(function () {

                    $("#btnTrial").click(function (e) {
    
                        e.preventDefault();
                        $("#btnTrial").attr('disabled', 'disabled');
    
                        var total = 5;
                        if (document.getElementById('<%=txtLoopRows.ClientID %>').value != "") {
                            var total = document.getElementById('<%=txtLoopRows.ClientID %>').value;
                        }
                        // comes here the first time
                        PageMethods.OperatePage(total, function (result) {
    
    
                            if (result) {
                                setTimeout($.updateProgressbar, 500);
                            }
                        });
                    });
                });
    

    _
    Public Shared Function OperatePage(total As Integer) As Object

        Dim session As HttpSessionState = HttpContext.Current.Session
    
        Dim totalParsed As Integer = 0
        Integer.TryParse(total.ToString(), totalParsed)
        \_TotalLoop = totalParsed  ' 1
    
        System.Threading.ThreadPool.QueueUserWorkItem(AddressOf ThreadProc, session)  '  Sets to invoke ThreadProc
    
        Return New With {.progress = 0}
    End Function
    

    _
    Public Shared Function ThreadProc(ByVal stateInfo As Object) '2
    ' Loops with sleep but sets StateVariable to the counter which is picked up by Progress Page then to $.updateProgressbar = function
    ' InfusionSoft stuff here
    Dim DefPage As New _Default
    DefPage.GetTable(stateInfo) ' Invokes but form variables are nothing

    F Offline
    F Offline
    F ES Sitecore
    wrote on last edited by
    #2

    GetTable is being kicked off from a background thread, it has no request context so has no server-side controls to access. Even if it did, you can't "push" data to the client that way, your server code isn't running inside the browser, it can't make changes to properties on server-side controls and have those instantly translated into DOM updates in the client html. Basically your architecture isn't going to work, you can't do what you're looking to do because it isn't compatible with how http works. You'll need a function on the client polling a method on the server via a timer, and have that method return the current state which you them show in the browser by updating the DOM from the javascript.

    Q 1 Reply Last reply
    0
    • Q QuickBooksDev

      I have a simple VB.Net web app that gets a large table based on Form controls and I need it display the progress such as Doing 'Record# nnn'. This method can be simulated with via clicking on a button the the form is initiated which is the instance that we need to access. lblMsg is a label on the form what I would like to update.

      Public Function GetTable
      Dim I as Integer
      for I = 1 to 10
      lblMsg.Text = "Doing Record# " & i
      Sleep 1000
      next
      End Function

      We are currently trying the below but when GetTable gets control lblMsg is nothing which means that the form is not initialed. How can I get this to work?

      $(document).ready(function () {

                      $("#btnTrial").click(function (e) {
      
                          e.preventDefault();
                          $("#btnTrial").attr('disabled', 'disabled');
      
                          var total = 5;
                          if (document.getElementById('<%=txtLoopRows.ClientID %>').value != "") {
                              var total = document.getElementById('<%=txtLoopRows.ClientID %>').value;
                          }
                          // comes here the first time
                          PageMethods.OperatePage(total, function (result) {
      
      
                              if (result) {
                                  setTimeout($.updateProgressbar, 500);
                              }
                          });
                      });
                  });
      

      _
      Public Shared Function OperatePage(total As Integer) As Object

          Dim session As HttpSessionState = HttpContext.Current.Session
      
          Dim totalParsed As Integer = 0
          Integer.TryParse(total.ToString(), totalParsed)
          \_TotalLoop = totalParsed  ' 1
      
          System.Threading.ThreadPool.QueueUserWorkItem(AddressOf ThreadProc, session)  '  Sets to invoke ThreadProc
      
          Return New With {.progress = 0}
      End Function
      

      _
      Public Shared Function ThreadProc(ByVal stateInfo As Object) '2
      ' Loops with sleep but sets StateVariable to the counter which is picked up by Progress Page then to $.updateProgressbar = function
      ' InfusionSoft stuff here
      Dim DefPage As New _Default
      DefPage.GetTable(stateInfo) ' Invokes but form variables are nothing

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #3

      I don't how you came up with that code, and it sort of looks like your a windows programmer trying to write a web form. In code block 1, not sure why your using sleep, you sort of want the code to run as fast as possible. In code block 2, you have a weird mixture of JQuery and Javascript. So I just figured out that you just want to show a progress image or something, or you just want to call the service and create a pause as if code is running or something. To show a progress, you just make a modal overlay using div, and just show and hide it using the client script. This is how client script via web service works, Introduction to using jQuery with Web Services[^]

      Q 1 Reply Last reply
      0
      • F F ES Sitecore

        GetTable is being kicked off from a background thread, it has no request context so has no server-side controls to access. Even if it did, you can't "push" data to the client that way, your server code isn't running inside the browser, it can't make changes to properties on server-side controls and have those instantly translated into DOM updates in the client html. Basically your architecture isn't going to work, you can't do what you're looking to do because it isn't compatible with how http works. You'll need a function on the client polling a method on the server via a timer, and have that method return the current state which you them show in the browser by updating the DOM from the javascript.

        Q Offline
        Q Offline
        QuickBooksDev
        wrote on last edited by
        #4

        Yea, so much for hiring somebody to do it. So how can I get the lblMsg.text pushed to the web form so that the user can see the progress i.e. Doing Record# nnn???

        F 1 Reply Last reply
        0
        • Q QuickBooksDev

          Yea, so much for hiring somebody to do it. So how can I get the lblMsg.text pushed to the web form so that the user can see the progress i.e. Doing Record# nnn???

          F Offline
          F Offline
          F ES Sitecore
          wrote on last edited by
          #5

          [WebMethod]
          public static string GetProgress()
          {
          // just returning ticks as it is a number that constantly goes up
          // you'll need to get your actual progress

          return DateTime.Now.Ticks.ToString();
          

          }

          <div id="progress">

          </div>

          <script type="text/javascript">
          var t = window.setInterval(showProgress, 1000);
          var p = $("#progress");

          function showProgress()
          {
              $.ajax({
                  type: "POST",
                  url: "test.aspx/GetProgress",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (data) {
                      p.html('Progress: ' + data.d);
                      // to cancel the polling
                      // clearInterval(t);
                  }
              });
          }
          

          </script>

          Q 1 Reply Last reply
          0
          • J jkirkerx

            I don't how you came up with that code, and it sort of looks like your a windows programmer trying to write a web form. In code block 1, not sure why your using sleep, you sort of want the code to run as fast as possible. In code block 2, you have a weird mixture of JQuery and Javascript. So I just figured out that you just want to show a progress image or something, or you just want to call the service and create a pause as if code is running or something. To show a progress, you just make a modal overlay using div, and just show and hide it using the client script. This is how client script via web service works, Introduction to using jQuery with Web Services[^]

            Q Offline
            Q Offline
            QuickBooksDev
            wrote on last edited by
            #6

            I am not a web developer so please bear with me. 1. Sleep used to simulate long running process getting records from a large database from a web service and processing same in the server. 2. The java stuff was done by a developer that I hired who could not do what was needed. He is now gone. 3. I want to push the status / progress which may take 5-10 minutes and I want the user to see the progress i.e. Doing Record#=nn, Added=nn, etc. 4. I am happy with keeping the div showing all the time but the problem is that normally the web page does not get updated until the process is finished. For a long running process the user will give up after a minute unless he sees a change. 5. I am not sure what a modal div is but seems to imply that things wait until the modal div has completed something or the user hit a button. This is NOT what is needed.

            J 1 Reply Last reply
            0
            • F F ES Sitecore

              [WebMethod]
              public static string GetProgress()
              {
              // just returning ticks as it is a number that constantly goes up
              // you'll need to get your actual progress

              return DateTime.Now.Ticks.ToString();
              

              }

              <div id="progress">

              </div>

              <script type="text/javascript">
              var t = window.setInterval(showProgress, 1000);
              var p = $("#progress");

              function showProgress()
              {
                  $.ajax({
                      type: "POST",
                      url: "test.aspx/GetProgress",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: function (data) {
                          p.html('Progress: ' + data.d);
                          // to cancel the polling
                          // clearInterval(t);
                      }
                  });
              }
              

              </script>

              Q Offline
              Q Offline
              QuickBooksDev
              wrote on last edited by
              #7

              Thanks I need the actual count in the background server code which must use the web form to get paramenters, etc. How does the above fit in with the existing code? Do I remove it? or is this is combination with it?

              F 1 Reply Last reply
              0
              • Q QuickBooksDev

                Thanks I need the actual count in the background server code which must use the web form to get paramenters, etc. How does the above fit in with the existing code? Do I remove it? or is this is combination with it?

                F Offline
                F Offline
                F ES Sitecore
                wrote on last edited by
                #8

                It depends what your gettable method is doing. I suspect you're trying to push html to the client which asp.net doesn't really support, the page has to be made in one go then sent to the client in one go, you can't do it in chunks (you can look at disabling buffering though, it might work, Response.Buffer = false). Chances are you're going to have to re-architect this and rather than generating the table in a background thread, have your javascript function keep calling a web method that returns the data 10 or 50 rows at a time then create the table html via javascript as each batch comes back. That way the page stays responsive and gradually loads. Doing it the other way and trying to write the table bit by bit might not work. Google for retrieving data via ajax, and building a table via ajax, you should get sample code of both.

                Q 1 Reply Last reply
                0
                • F F ES Sitecore

                  It depends what your gettable method is doing. I suspect you're trying to push html to the client which asp.net doesn't really support, the page has to be made in one go then sent to the client in one go, you can't do it in chunks (you can look at disabling buffering though, it might work, Response.Buffer = false). Chances are you're going to have to re-architect this and rather than generating the table in a background thread, have your javascript function keep calling a web method that returns the data 10 or 50 rows at a time then create the table html via javascript as each batch comes back. That way the page stays responsive and gradually loads. Doing it the other way and trying to write the table bit by bit might not work. Google for retrieving data via ajax, and building a table via ajax, you should get sample code of both.

                  Q Offline
                  Q Offline
                  QuickBooksDev
                  wrote on last edited by
                  #9

                  I understand that normally you get a server request and one page goes out and that is what I was really hoping to get around somehow. GetTable does just that. It gets a database table from a Web Service based on form controls and populates a grid. It also writes it to disk for potential downloads. I was hoping that this technology to update the lblMsg status could be used in other programs for a bunch of similar things. Putting in some java to keep requesting a chunk might work in this case but in our other programs it would not or at least not easily. In the other programs the code would be much more complex and could not be done in chunks since the processing id dependent upon what it did in the records prior. My thought is that since there are push technologies out there i.e. Chats do not need a user to push a button to get what other people enter, same for streaming that there must be a way of doing the same in my simple case. I have read about keeping sessions opened, etc. but since I am not a web developer I have a hard time getting my head around it. As an alternative I was thinking of changing the lblMsg.text to s variable lblMsg_text that perhaps the async methods could just use to populate the real lblMsg.txt via Java. Would there be a way for that to work. I would have to be an instantiated variable since multiple users could be using it.

                  1 Reply Last reply
                  0
                  • Q QuickBooksDev

                    I am not a web developer so please bear with me. 1. Sleep used to simulate long running process getting records from a large database from a web service and processing same in the server. 2. The java stuff was done by a developer that I hired who could not do what was needed. He is now gone. 3. I want to push the status / progress which may take 5-10 minutes and I want the user to see the progress i.e. Doing Record#=nn, Added=nn, etc. 4. I am happy with keeping the div showing all the time but the problem is that normally the web page does not get updated until the process is finished. For a long running process the user will give up after a minute unless he sees a change. 5. I am not sure what a modal div is but seems to imply that things wait until the modal div has completed something or the user hit a button. This is NOT what is needed.

                    J Offline
                    J Offline
                    jkirkerx
                    wrote on last edited by
                    #10

                    Oh, I thought you were a programmer, I apologize for the mistake. As far as the progress goes, just depends on the UI design. I've been ditching the Modal Progress lately, for just swapping out the data input container for a progress container and then switching to a result container all in the same space. Sort of like tabs but with no tabs. Pushing the status to the progress container would be tricky. I'm trying to think of a way to do that. I guess I would write jquery to send data in small chunks, and display the results of that chunk, in a loop format. Sounds like you need some help in programming.

                    Q 1 Reply Last reply
                    0
                    • J jkirkerx

                      Oh, I thought you were a programmer, I apologize for the mistake. As far as the progress goes, just depends on the UI design. I've been ditching the Modal Progress lately, for just swapping out the data input container for a progress container and then switching to a result container all in the same space. Sort of like tabs but with no tabs. Pushing the status to the progress container would be tricky. I'm trying to think of a way to do that. I guess I would write jquery to send data in small chunks, and display the results of that chunk, in a loop format. Sounds like you need some help in programming.

                      Q Offline
                      Q Offline
                      QuickBooksDev
                      wrote on last edited by
                      #11

                      I am a programmer but not for web apps. 40+ years of programming. I am not family with jQuery and have very basic Java knowledge. Need the techniques to be used. In vb.Net windows desktop you can bring up a modal screen or MessageBox but that stops everything. I do not want the progress indication to stop anything. The problem is not switching visible to invisible div's or controls but getting the data from / to controls and the 'running' form. I am not trying to populate the grid in periodically but the progress i.e. lblMsg.text = "Doing Record#=nnn"

                      J 1 Reply Last reply
                      0
                      • Q QuickBooksDev

                        I am a programmer but not for web apps. 40+ years of programming. I am not family with jQuery and have very basic Java knowledge. Need the techniques to be used. In vb.Net windows desktop you can bring up a modal screen or MessageBox but that stops everything. I do not want the progress indication to stop anything. The problem is not switching visible to invisible div's or controls but getting the data from / to controls and the 'running' form. I am not trying to populate the grid in periodically but the progress i.e. lblMsg.text = "Doing Record#=nnn"

                        J Offline
                        J Offline
                        jkirkerx
                        wrote on last edited by
                        #12

                        I make windows applications, so I know that the messagebox stops the message pump running in the Windows OS. The thing here is, your working with HTTP protocol, and you have to obey the rules of it. On top of that, your working with HTML, which are elements, and not objects, sorry for the correction. So with the HTTP protocol, it's pretty much get and post, get a page, post a page back to the server. It would be a waste of time to keep submitting the form back for each piece of data transmitted, to show detailed progress. So you use a client script, that runs on the browser, to transmit each piece of data in the background, and change the DOM. The DOM is the collection of HTML that is downloaded from the server making up a web page. You can alter the HTML elements, delete, append, change text by manipulating the DOM using Javascript or JQuery. A working example here, that switches address input to progress, fetches the address, populates the textboxes, switches back to address input. I would experiment, or just write code that gets each line of data on your form, and run the AJAX call to web service in a loop, creating new HTML for each record processed. So instead a progress, they just see the data uploading, and new HTML records created. This would fool or give the illusion of progress, without having a bar or wheel. I suppose a fake progress sort of message box could be made with an HTML div that expands in witdh, colored green or blue. If you look at my Tip, I wrote a filmstrip that just loops, until the end is reached. The same principal could apply for your solution, in which 1 function just calls another function, until the end is reached. The primary function collects the data, the child function posts the data, and prints a result. If you need help on this, you can private message me. Display Advertising Filmstrip[^]

                        function Selected_Shipping_Address_Load(m_Data1) {

                        var panel\_CardInfo = $('\[id\*="\_panel\_MP\_CardInfo\_Container"\]');
                        var panel\_Progress = $('\[id\*="\_panel\_MP\_Progress\_Container"\]');    
                        
                        if (panel\_CardInfo.css('display') === 'inline-block') {
                            panel\_CardInfo.css('display', 'none');
                            panel\_Progress.css('display', 'inline-block');
                        }
                        else {
                            panel\_CardInfo.css('display', 'none');
                            panel\_Progress.css(
                        
                        Q 1 Reply Last reply
                        0
                        • J jkirkerx

                          I make windows applications, so I know that the messagebox stops the message pump running in the Windows OS. The thing here is, your working with HTTP protocol, and you have to obey the rules of it. On top of that, your working with HTML, which are elements, and not objects, sorry for the correction. So with the HTTP protocol, it's pretty much get and post, get a page, post a page back to the server. It would be a waste of time to keep submitting the form back for each piece of data transmitted, to show detailed progress. So you use a client script, that runs on the browser, to transmit each piece of data in the background, and change the DOM. The DOM is the collection of HTML that is downloaded from the server making up a web page. You can alter the HTML elements, delete, append, change text by manipulating the DOM using Javascript or JQuery. A working example here, that switches address input to progress, fetches the address, populates the textboxes, switches back to address input. I would experiment, or just write code that gets each line of data on your form, and run the AJAX call to web service in a loop, creating new HTML for each record processed. So instead a progress, they just see the data uploading, and new HTML records created. This would fool or give the illusion of progress, without having a bar or wheel. I suppose a fake progress sort of message box could be made with an HTML div that expands in witdh, colored green or blue. If you look at my Tip, I wrote a filmstrip that just loops, until the end is reached. The same principal could apply for your solution, in which 1 function just calls another function, until the end is reached. The primary function collects the data, the child function posts the data, and prints a result. If you need help on this, you can private message me. Display Advertising Filmstrip[^]

                          function Selected_Shipping_Address_Load(m_Data1) {

                          var panel\_CardInfo = $('\[id\*="\_panel\_MP\_CardInfo\_Container"\]');
                          var panel\_Progress = $('\[id\*="\_panel\_MP\_Progress\_Container"\]');    
                          
                          if (panel\_CardInfo.css('display') === 'inline-block') {
                              panel\_CardInfo.css('display', 'none');
                              panel\_Progress.css('display', 'inline-block');
                          }
                          else {
                              panel\_CardInfo.css('display', 'none');
                              panel\_Progress.css(
                          
                          Q Offline
                          Q Offline
                          QuickBooksDev
                          wrote on last edited by
                          #13

                          Thanks let me play with that technique.

                          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