Reading Request.Form variables from ASP.NET to Classic ASP page

Daspoo

Regular
Joined
Jan 27, 2003
Messages
99
Location
Fort Walton Beach, Florida
Hey all. Does anyone know if its possible to have a classic ASP page read the values of controls on an ASP.NET (.aspx) page using Request.Form once the .aspx page submits to the .asp page? I know it's possible from classic ASP to ASP.NET, but I'm curious if its possible in the reverse direction. I've tried it and it doesn't appear to be working, but I'm possibly doing something wrong. Any help would be most appreciated! Thanks all!

-= Daspoo =-
 
Hmm...swore I wouldn't be one of those guys that would just post a question, get a response and then bail... :D So, with that said, I figured out what I needed to do. There's a BIG difference between declaring <asp:__></asp> controls in the HTML view of a .aspx page, and HTML controls (e.g., <input>) in the same view on the same page. What I ended up having to do was to:

1) Place all info I needed in hidden <asp:textbox> controls on one .aspx page (WebForm1):
Code:
<div style="DISPLAY: none">
    <asp:textbox id="txt1" runat="server"></asp:textbox>
    <asp:textbox id="txt2" runat="server"></asp:textbox>
</div>

2) Create and set up a second .aspx page (WebForm2) to read the values of those controls:
Code:
' Place this in the class definition of the page under the [I]Inherits System.Web.UI.Page[/I] statement
Public firstPage as WebForm1

' Place this in the Page_Load routine
firstPage = CType(Context.Handler, WebForm1)

3) Grab the values from WebForm1 and shove as the values of <input> tag hidden variables for the classic ASP target page to read (also in the Page_Load routine):
Code:
' Define the form
Response.Write("<form name=""frmWebForm2"" method=""post"" action=""target_asp_page.asp"">")

' Declare the hidden variable(s)
Response.Write("<input type=""hidden"" name=""hid1"" value=""" & firstPage.txt1 & """>")
Response.Write("<input type=""hidden"" name=""hid2" value=""" & firstPage.txt2 & """>")
...etc...

' End the <form> tag
Response.Write("</form>")

' Finally, redirect to the appropriate target ASP page defined in the <form> tag ("action" value)
Response.Write("<script language=""Javascript"" type=""text/javascript"">frmWebForm2.submit();</script>")

Once the classic ASP page is loaded, it is now able to access the values of the "hid1" and "hid2" hidden variables.

Hope this helps others out there... not tough stuff, but did take me a while to figure out. Good luck! :cool:
 
Last edited:
Made a mistake in the previous post... check this one for the correct info. Thanks!

........................................................................................................

1) Place all info I needed in hidden <asp:textbox> controls on one .aspx page (WebForm1):
Code:
<div style="DISPLAY: none">
    <asp:textbox id="txt1" runat="server"></asp:textbox>
    <asp:textbox id="txt2" runat="server"></asp:textbox>
</div>

2) Create properties on the form (WebForm1) that will later be accessed by the second form (WebForm2):
Code:
Public ReadOnly Property myProp1() As String
    Get
        ' Return the value of the hidden textbox
        Return txt1.Text.ToString
    End Get
End Property

Public ReadOnly Property myProp2() As String
    Get
        ' Return the value of the hidden textbox
        Return txt2.Text.ToString
    End Get
End Property

3) Create and set up a second .aspx page (WebForm2) to read the values of those properties:
Code:
' Place this in the class definition of the page under the [I]Inherits System.Web.UI.Page[/I] statement
Public firstPage as WebForm1

' Place this in the Page_Load routine
firstPage = CType(Context.Handler, WebForm1)

4) Grab the values from the WebForm1 Properties and shove as the values of <input> tag hidden variables for the classic ASP target page to read (also in the Page_Load routine):
Code:
' Define the form
Response.Write("<form name=""frmWebForm2"" method=""post"" action=""target_asp_page.asp"">")

' Declare the hidden variable(s)
Response.Write("<input type=""hidden"" name=""hid1"" value=""" & firstPage.myProp1 & """>")
Response.Write("<input type=""hidden"" name=""hid2" value=""" & firstPage.myProp2 & """>")
...etc...

' End the <form> tag
Response.Write("</form>")

' Finally, redirect to the appropriate target ASP page defined in the <form> tag ("action" value)
Response.Write("<script language=""Javascript"" type=""text/javascript"">frmWebForm2.submit();</script>")

Once the classic ASP page is loaded, it is now able to access the values of the "hid1" and "hid2" hidden variables.

Hope this helps others out there... not tough stuff, but did take me a while to figure out. Good luck! :cool:
 
Back
Top