Passing variables from classical ASP to ASP.NET

Discussion in 'ASP.NET / ASP.NET Core' started by wisemx, Jan 22, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. If you don't want to use a query or session why not save the value in a database?


    Both asp and asp.net would have access to the record/value that way.
     
  2. Hello,

    I've been googling this issue for 2 days now and but I haven't found a satisfying answer, so here I am, basically I am looking to find a good way to send variables (non-session)from ASP page to ASP.NET page and display it in ASP.NET page...

    Now I also dont want to deal with querystrings, I do not want to have the values of these variables visiblein the address bar..

    So I figured I use a simple HTML form in ASP put the variables I want to send as hidden input type and post them using javascript to .aspx file like so:
    This is code from .asp file:
    Iftransferdn <> "" Then
    %>
    <form name="amt" method="POST" action="transferdn.aspx">
    <INPUT TYPE=hidden NAME=total VALUE=<%=total%>>
    </form>
    <script>document.forms[0].submit()</script>
    <%
    '(total is a previously defined variable, everything is working correctly here I think)

    And here is the line in .aspx file that receives this info:
    .
    .
    .

    <% Dim total as String
    total = Request.Form("total")
    %>
    .
    .
    .
    <td><asp:textbox id="totalamt" runat="server" width="144px"><%=total%></asp:textbox></td>

    and it gives me a parcer error on the line above, why? I dont know, but hopefully someone will help me out with this, I am not too familiar with ASP.NET so maybe there is just some tiny thing I am missing or maybe I am doing this completely wrong, I just dont know and searching this online has not been helpful so far, I am planning to pass quite a few variables this way so it's important for me to find a way to do this and if you know of any other ways of doing this better please let me know..

    Thanks in advance..
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    You should be able to use POST to pass variable between ASP / ASP.NET pages.


    A parser error usually means the code has some syntax issues. Can you post the exact error and the code?


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. Hello, thank you for your responses,


    Yes I have thought about adding an extra table to my database just for this transaction, I guess that is one solution but because the information I am sending is user specific it would require much more codeto make sure the ASP.NET page retrives the right user information and as I mainly work with ASP and not ASP.NET I just dont know how to even access my database from ASP.NET so it will require even more time on my part to search for more solutions, but actually I am still thinking about this option, do you know if its more secure than doing a post?


    Although simply posting infromation to ASP.NET site is a lot easier I think [​IMG]I just wonder how secure it is?


    but even that is not working for me right now, well here is the code and the error message, I think I am very close to getting it to work but not close enough apparently...



    Server Error in '/BLACK' Application.


    Parser Error


    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Code blocks are not supported in this context.

    Source Error:





    Code:
    Line 96: <tr>
    Line 97: <td noWrap align="right">Amount:</td>
    Line 98: <td><asp:textbox id="txtTransactionAmount" runat="server" width="144px"><%=total%></asp:textbox></td>
    Line 99: </tr>
    Line 100:<tr>
    Source File: /BLACK/icharge.aspx Line: 98






    Version Information:Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210


    And here is the asp code (the code file is very big and everything works besides this post thing so I am just going to put the code I added to make this work):
    Iftransferdn <> "" Then
    %>
    <form name="amt" method="POST" action="icharge.aspx">
    <INPUT TYPE=hidden NAME=total VALUE=<%=total%>>
    </form>
    <script>document.forms[0].submit()</script>
    <%

    And the error is generated on this asp.net file (once again everything in this file worked before I added the 'post' code):
    <%@ Page Language="c#" Inherits="ibpaspx.icharge" CodeFile="icharge.aspx.cs" %>
    <%@ Register Assembly="nsoftware.IBizPayWeb" Namespace="nsoftware.IBizPay" TagPrefix="cc1" %>
    <HTML>
    <HEAD>
    <title></title>
    <LINK href="stylesheet.css" type="text/css" rel="stylesheet">
    </HEAD>

    <% Dim total as String
    total = Request.Form("total")
    %>
    <form id="form" method="post" runat="server">
    ................................
    <td><asp:textbox id="txtTransactionAmount" runat="server" width="144px"><%=total%></asp:textbox></td>
    </tr>
    <tr>
    <td noWrap align="right">Description:
    </td>
    ................................

    Thanks in advance,
     
  5. You cannot assign a value to an ASP.NET control using a code block.Instead, set the 'Text' property of the textbox control from within the '<script></script> ' and not '<% %> on your aspx page.

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  6. Alright, well basically after about5 hours of taking all the wrong turns with this and being frustrated I learned abit about how ASP.NET works and how my variables were not correctly defined on my ASP page.....
    But I finally figured it out and I wanted to share the code herewith you just in case anyone else will have the same problem...

    So the ASP code is:

    Function open_icharge(total)
    %>
    <form name="totalamount" method="POST" action="icharge.aspx" target = "_top">
    <INPUT TYPE=hidden NAME="total" ID = "total" VALUE="<%response.Write(total)%>">
    </form>
    <script>document.totalamount.submit()</script>
    <%
    End Function

    And ASP.NET code is (put this before HTML tag code):
    <script runat="server">
    void Page_Load()
    {
    txtTransactionAmount.Text = Request.Form["total"];
    }


    </script>


    /// and then put your text boxes for each parameter you want to post over


    <asp:textbox id="txtTransactionAmount" runat="server" width="144px"></asp:textbox>
    Thanks everyone for the responses, it feels good to be done with something[​IMG]
     
  7. Bruce

    Bruce DiscountASP.NET Staff

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page