Pass a long parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pinky8
    New Member
    • Aug 2008
    • 14

    Pass a long parameter

    I have an ASP page with a button and other things.
    When the button is clicked, it executes a javascript function which does:

    Code:
    	   document.Form1.method = 'post';
    	   document.Form1.action = "AnotherASPpage.asp?p1=" + allFields1 + "&p2=" + allFields2 + "&p3=" + bVar;
    	   document.Form1.submit();
    allFields1 represents all the fields in category 1 that user has selected. The fields are delimited by comma.
    allFields2 represents all the fields in category 2 that user has selected. The fields are delimited by comma.

    The AnotherASPpage. asp is supposed to display the result in Excel spreadsheet.

    I test it by selecting 15 fields in category 1 and it pops up a File Download small window asking if I want to Open, Save, or Cancel the Excel file. It shows an Excel name like abc.xls in the Name: section in that small window. I can Save the file successfully.

    But, when I select 16 fields in category 1, pops up a File Download small window asking if I want to Open, Save, or Cancel the Excel file. But, it doesn't show an Excel name like abc.xls in the Name: section in that small window. It shows ..., id1%20AS%20... When I click Save, it gives error about IE can't download ...&p3=...

    It looks like the limit of the querystring in the URL is too long. But with POST method the limit is huge and I'm no where near that limit.

    I am thinking about using hidden variables to pass data from one page to another but I can't because onclick of a button page1 invokes a javascript function which submits AnotherASPpage. asp and thus doesn't know about the hidden variables from page1.

    Can someone please help? Thanks.
    Last edited by DrBunchman; Aug 14 '08, 04:14 PM. Reason: Added [Code] Tags - Please use the '#' button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi pinky,

    Notice that, although you specify Post as your method, you are still passing values by adding them to the querystring.

    Can you not just use a submit button which will submit your form to the specified page and used hidden variables and controls to pass all the values through the form?

    Dr B

    Comment

    • pinky8
      New Member
      • Aug 2008
      • 14

      #3
      Hi Dr B,

      After user selects all the fields, there's need to have a way to tell the program to query the data and display the result in Excel. The button is a way to let the user do that. I don't know how to signal that differently.

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Is there a reason why you can't do the following:

        Code:
        <form name="form1" action="ProcessExcelPage.asp" method="post">
            <input name="hidden1" type="hidden" value="test" />
            <input name="txtbox1" type="text" />
            <input type="submit" value="Export to Excel" />
        </form>
        By setting the form's action property to the name of the page that passes the results to Excel you will pass the values of all the controls and hidden variables in your form via a Post.

        If this won't work then please explain what I am missing! :-)

        Let me know,

        Dr B

        Comment

        • pinky8
          New Member
          • Aug 2008
          • 14

          #5
          Dr B,

          Here's the sequence of events:
          1) page1.asp is rendered
          2) user selects some fields from page1 and click the button
          3) page1.asp invokes a javascript function which gets all of the selected fields and pass that to AnotherASPpage. I don't think the hidden1 variable that you set in page1.asp can grab whatever the user has selected. That was why I used javascript function to grab it.
          4) page1.asp redirects to AnotherASPpage which needs to know which fields
          the user selected.
          5) AnotherASPpage. asp queries the database for those selected fields and
          displays the result in Excel.
          6) user still sees page1.asp and doesn't see AnotherASPpage. asp at all.

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by pinky8
            3) page1.asp invokes a javascript function which gets all of the selected fields and pass that to AnotherASPpage. I don't think the hidden1 variable that you set in page1.asp can grab whatever the user has selected. That was why I used javascript function to grab it. .
            You can set the value of a hidden variable with javascript the same way you set the querystring
            Code:
                  document.Form1.method = 'post';
                         document.Form1.hidden1.value = allFields1;
                         document.Form1.hidden2.value = allFields2;
                         document.Form1.hidden3.value = bVar;
                         document.Form1.submit();
            I'm not a javascript guru, but this should work (whether this follows best practices, I have no idea)

            Let me know if this helps.

            Jared

            Comment

            • pinky8
              New Member
              • Aug 2008
              • 14

              #7
              Jared, thank you, that works but that doesn't fix the problem.
              I thought may be the request string is too long and thus caused Excel report cannot be downloaded. After using 3 hidden variables and don't pass any parameter in the URL, I get the following message:

              "Microsoft Office Excel cannot access the file There are several possible reasons:

              • The file name or path does not exist.
              • The file is being used by another program.
              • The workbook you are trying to save has the same name as a currently open workbook."

              It doesn't error all the time. The error occurs only when the hidden variables' values are longer, e.g. it works fine if hiddenvar1=1,2, 3,4,5,6,7,8,9,1 0,11,12,13,14,1 5,16,17,18,19,2 0,21,22
              but it will error when hiddenvar1=1,2, 3,4,5,6,7,8,9,1 0,11,12,13,14,1 5,16,17,18,19,2 0,21,22,23

              hiddenvar2=
              hiddenvar3=0

              The codes work perfectly fine in the development environment but not in production. I run both codes from the client machine which has Excel 2007.

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                I think the problem must be on the handler page. Could you do this?
                Code:
                for each x in request.form
                   response.write x & ": " & request.form(x) & "<br>" & vbNewLine
                next
                and tell me what the output is for the cases when the input is too long or when it is OK.

                Jared

                Comment

                • pinky8
                  New Member
                  • Aug 2008
                  • 14

                  #9
                  Hi Jared,

                  I add your code to AnotherASPpage. asp and below is the result:

                  when the input is is OK:

                  hiddenId:
                  hiddenS1:
                  textBox1:
                  textBox2:
                  textBox3:
                  hiddenVar1: 1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22
                  hiddenVar2:
                  hiddenVar3: 0


                  when the input is too long:

                  hiddenId:
                  hiddenS1:
                  textBox1:
                  textBox2:
                  textBox3:
                  hiddenVar1: 1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23
                  hiddenVar2:
                  hiddenVar3: 0


                  AnotherASPpage. asp does a request() of the hidden and textbox values.


                  I don't know if it has to do with the AddHeader or ContentType.
                  The following code used to outputs to Excel 2003 fine. Do I need to change it
                  to output to Excel 2007? I don't know when it started to break, whether when the input was too long or when it was switched to Excel 2007. I'm leaning toward the former.
                  <%
                  Response.Conten tType = "applicatio n/vnd.ms-excel"
                  Response.AddHea der "Content-Disposition", "attachment ; filename=List.x ls"
                  %>

                  When the input is is OK, it pops up a small "File Download - Security Warning" window showing
                  Name: List.xls
                  Type: MS Excel 97-2003 Worksheet, 2.66 MB
                  and it displays the output in Excel fine.

                  But when the input is too long, it pops up a small "File Download - Security Warning" window showing
                  Name: MyAspPage_asp (instead of List.xls)
                  Type: MS Excel 97-2003 Worksheet, 416 bytes
                  and when I click on Save it shows error:
                  IE cannot download MyAspPage.asp
                  and if I click Open instead of Save it will pop up a small Microsoft Office
                  Excel window with the following error:
                  "Microsoft Excel cannot access the file
                  ' 'https://www.myurl.com/dir1/MyAspPage.asp'. There are several possible
                  reasons:
                  - The file name or path name does not exist.
                  - The file you're trying to open is being used by another program. Close
                  the document in the other program, and try again.
                  - The name of the workbook you're trying to save is the same as the name
                  of another document that is read-only. Try saving the workbook with a
                  different name."
                  Last edited by pinky8; Aug 25 '08, 01:05 PM. Reason: add more text

                  Comment

                  • jhardman
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3405

                    #10
                    The good news is there is definitely no problem in the posted data. Up to the point that AnotherASPPage. asp opens the request collection there is definitely no problem.

                    The bad news is we still don't know where it is going bad. Could you print your code for how the xls file is opened and sent to the user? That miht give us some insight.

                    Jared

                    Comment

                    • pinky8
                      New Member
                      • Aug 2008
                      • 14

                      #11
                      The two .asp files/codes are long and contain some proprietary information that I'm not allowed to post their contens here. but here's a re-cap of the sequence of events:
                      1) page1.asp is rendered
                      2) user selects some fields from page1 and click the button
                      3) page1.asp invokes a javascript function which gets all of the selected fields and pass that to AnotherASPpage. I don't think the hidden1 variable that you set in page1.asp can grab whatever the user has selected. That was why I used javascript function to grab it.
                      4) page1.asp redirects to AnotherASPpage which needs to know which fields
                      the user selected.
                      5) AnotherASPpage. asp queries the database for those selected fields and
                      displays the result in Excel.
                      6) user still sees page1.asp and doesn't see AnotherASPpage. asp at all.

                      The culprit is it is trying to download the MyAspPage_asp instead of List.xls (when the input is too long, it pops up a small "File Download - Security Warning" window showing
                      Name: MyAspPage_asp (instead of List.xls)

                      It seems like the problem was fixed with Excel 1997 SP1. Could it be the same problem occurs in Excel 2007 and has nothing to do with my codes at all?

                      By the way, how can I change the following two lines of codes so that it won't prompt a message saying you're trying to open a List.xls that is in a different format than specified by the file extension. That message occurs only after I switched over to Excel 2007 from Excel 2003.
                      <%
                      Response.Conten tType = "applicatio n/vnd.ms-excel"
                      Response.AddHea der "Content-Disposition", "attachment ; filename=List.x ls"
                      %>

                      Comment

                      • NitinSawant
                        Contributor
                        • Oct 2007
                        • 271

                        #12
                        ,

                        Hi pinky8,
                        you can use Cache object to store the values from page1.asp and access that values on anotherPage.asp from Cache.

                        There are two methods to add data to cache object,
                        1) Cahce.Insert
                        2) Cache.Add
                        e.g
                        to insert
                        Code:
                        Cache.Insert("key","value");
                        to access data from Cache object
                        Code:
                        if(Cache["key"]!=null)
                        {
                             txtExample.Text=(String)Cache("key");
                        }
                        hope this helps.

                        regards, Nitin Sawant.
                        Last edited by NitinSawant; Aug 26 '08, 05:41 PM. Reason: +=

                        Comment

                        • pinky8
                          New Member
                          • Aug 2008
                          • 14

                          #13
                          Hi Nitin,

                          Do you mean to use cache object instead of hidden variables?

                          Comment

                          • jhardman
                            Recognized Expert Specialist
                            • Jan 2007
                            • 3405

                            #14
                            Originally posted by pinky8
                            3) page1.asp invokes a javascript function which gets all of the selected fields and pass that to AnotherASPpage. I don't think the hidden1 variable that you set in page1.asp can grab whatever the user has selected. That was why I used javascript function to grab it.
                            You need to use a javascript function regardless to capture the inputs, otherwise the hidden input is just a blank input. One of your earlier questions asked how to avoid sending the data in the querystring. Realistically, the only other option you have is to send the data as a form input. You do this by changing your javascript function to add the data to the form input rather than the querystring.
                            4) page1.asp redirects to AnotherASPpage which needs to know which fields
                            the user selected.
                            5) AnotherASPpage. asp queries the database for those selected fields and
                            displays the result in Excel.
                            6) user still sees page1.asp and doesn't see AnotherASPpage. asp at all.
                            Still, I'm pretty sure the error is on AnotherASPpage. asp, not on page1.asp
                            The culprit is it is trying to download the MyAspPage_asp instead of List.xls (when the input is too long, it pops up a small "File Download - Security Warning" window showing
                            Name: MyAspPage_asp (instead of List.xls)

                            It seems like the problem was fixed with Excel 1997 SP1. Could it be the same problem occurs in Excel 2007 and has nothing to do with my codes at all?

                            By the way, how can I change the following two lines of codes so that it won't prompt a message saying you're trying to open a List.xls that is in a different format than specified by the file extension. That message occurs only after I switched over to Excel 2007 from Excel 2003.
                            <%
                            Response.Conten tType = "applicatio n/vnd.ms-excel"
                            Response.AddHea der "Content-Disposition", "attachment ; filename=List.x ls"
                            %>
                            I'm not sure if the application/vnd... line needs to be changed, it is possible, but Excel 2007 doesn't use the same file extension so the second line needs to be "...xlsx" - try that change and see if it helps.

                            Jared

                            Comment

                            • jhardman
                              Recognized Expert Specialist
                              • Jan 2007
                              • 3405

                              #15
                              Originally posted by pinky8
                              Hi Nitin,

                              Do you mean to use cache object instead of hidden variables?
                              instead of the request collection. Nitin646, I've never seen a workup that uses this approach. I take it you've done this before?

                              Jared

                              Comment

                              Working...