469,578 Members | 1,869 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Pass a long parameter

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

Expand|Select|Wrap|Line Numbers
  1.        document.Form1.method = 'post';
  2.        document.Form1.action = "AnotherASPpage.asp?p1=" + allFields1 + "&p2=" + allFields2 + "&p3=" + bVar;
  3.        document.Form1.submit();
  4.  
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.
Aug 14 '08 #1
18 2578
DrBunchman
979 Expert 512MB
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
Aug 14 '08 #2
pinky8
14
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.
Aug 14 '08 #3
DrBunchman
979 Expert 512MB
Is there a reason why you can't do the following:

Expand|Select|Wrap|Line Numbers
  1. <form name="form1" action="ProcessExcelPage.asp" method="post">
  2.     <input name="hidden1" type="hidden" value="test" />
  3.     <input name="txtbox1" type="text" />
  4.     <input type="submit" value="Export to Excel" />
  5. </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
Aug 15 '08 #4
pinky8
14
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.
Aug 15 '08 #5
jhardman
3,406 Expert 2GB
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
Expand|Select|Wrap|Line Numbers
  1.       document.Form1.method = 'post';
  2.              document.Form1.hidden1.value = allFields1;
  3.              document.Form1.hidden2.value = allFields2;
  4.              document.Form1.hidden3.value = bVar;
  5.              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
Aug 15 '08 #6
pinky8
14
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,10,11,12,13,14,15,16, 17,18,19,20,21,22
but it will error when 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

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.
Aug 22 '08 #7
jhardman
3,406 Expert 2GB
I think the problem must be on the handler page. Could you do this?
Expand|Select|Wrap|Line Numbers
  1. for each x in request.form
  2.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  3. next
and tell me what the output is for the cases when the input is too long or when it is OK.

Jared
Aug 22 '08 #8
pinky8
14
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.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=List.xls"
%>

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."
Aug 25 '08 #9
jhardman
3,406 Expert 2GB
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
Aug 25 '08 #10
pinky8
14
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.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=List.xls"
%>
Aug 26 '08 #11
NitinSawant
270 100+
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
Expand|Select|Wrap|Line Numbers
  1. Cache.Insert("key","value");
  2.  
to access data from Cache object
Expand|Select|Wrap|Line Numbers
  1. if(Cache["key"]!=null)
  2. {
  3.      txtExample.Text=(String)Cache("key");
  4. }
  5.  
hope this helps.

regards, Nitin Sawant.
Aug 26 '08 #12
pinky8
14
Hi Nitin,

Do you mean to use cache object instead of hidden variables?
Aug 26 '08 #13
jhardman
3,406 Expert 2GB
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.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=List.xls"
%>
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
Aug 26 '08 #14
jhardman
3,406 Expert 2GB
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
Aug 26 '08 #15
NitinSawant
270 100+
Hi Nitin,

Do you mean to use cache object instead of hidden variables?
ya, you can use cache object instead of hidden variables
Aug 27 '08 #16
pinky8
14
I try the .xlsx and get error:
"Excel cannot open the file 'List.xlsx' because the file format or file extension is not valid."

I also try the cache but that doesn't resolve the problem.
Aug 27 '08 #17
pinky8
14
Response.Buffer = TRUE
Response.AddHeader "Content-disposition", "attachment; filename"
Response.ContentType = "application/vnd.ms-excel"

I think I know where the problem is. When I commented out the AddHeader and ContentType lines to output to the browser instead of Excel, I get error:

Response object error 'ASP 0251 : 80004005'

Response Buffer Limit Exceeded

/AnotherASPpage.asp, line 0

Execution of the ASP page caused the Response Buffer to exceed its configured limit.

The thing is it works fine in development environment but error in production. That means some configuration differences between the two environments. Do you know where that is to set or increase the buffer limit?
Aug 27 '08 #18
pinky8
14
I found a solution for it by using Response.Flush and that fixed the problem.
Thank you all for helping!
Aug 27 '08 #19

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Zlatko Matić | last post: by
29 posts views Thread by Why Tea | last post: by
6 posts views Thread by =?Utf-8?B?emlubw==?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.