views:

580

answers:

1

Hello,

Am trying to convert the content of a page to an Excel format, the problem is when I redirect the page I don't get my request variables so I found a solution that we should define a hiden variable for each request variable and then define the value after Get call. This is the code that am using now :

<script language="Javascript">
   function exportToExcel()
   {
     document.frm.hndExcel.value = "true";
     document.frm.submit();
   }
</script>


<form name="frm" method="get" action="LibGetStatistics.asp" ID="Form1">
 <% if Request.QueryString("hndExcel") = "true" then
    Response.ContentType = "application/vnd.ms-excel"
 end if%>

 <%= GetStatistics() %>
  <input type="hidden" name="hndExcel" value="false" ID="Hidden1">
  *<input type="hidden" name="ShowOverDueBooks" value="
         <%=Request.QueryString "ShowOverDueBooks")%>" ID="Hidden2">
  <input type="hidden" name="StartDate" value="
         <%=Request.QueryString("StartDate")%>" ID="Hidden3">
  <input type="hidden" name="EndDate" value="
         <%=Request.QueryString("EndDate")%>" ID="Hidden4">*

 <a href="JavaScript:exportToExcel();"><img src='vimages/excel.gif' border=0></a>
</form>

The problem is when I want to use this code in other forms I need to declare a hidden variable for each Request variables. Is there any other way to generalize this code so when we post back the page we keep the same request.

Thanks.

A: 

Again, After some trys I found a general solution that don't use the hidden variables, we have just to use the Request.QueryString property :

<script language="Javascript">
function exportToExcel()
{
    document.frm.hndExcel.value = "true";
    document.frm.action='LibGetStatistics.asp?' + '<%=Request.QueryString%>';
    document.frm.submit();
}
</script>


<form name="frm" method="post"  ID="Form1">
    <input type="hidden" name="hndExcel" value="false" ID="Hidden1">
    <% if Request.Form("hndExcel") = "true" then
     Response.ContentType = "application/vnd.ms-excel"
    end if%>

    <%= GetStatistics() %>
          <a href="JavaScript:exportToExcel();">
              <img src='vimages/excel.gif' border=0></a>
</form>

I hope that should help people who will face this problem.

Dreamer57