What am I doing wrong?

G

Guest

Hi,

I'm at my wits-end here. I'm a beginner with ASP/C# (using .NET 2003)
and I'm trying to post variables from a classic ASP form to a ASP.NET
form. The Classic ASP form was scripted with VBScript whereas the
ASP.NET page is scripted with C#.

My issue is this: I have two files within the site's working directory
(PaymentPage.aspx and PaymentPage.aspx.cs). The .cs file is the
codebehind for the aspx file. Basically, I can ouput the posted
variable from the top of the aspx file using:
<% Response.Write(Request.Form["totalcost"])); %>
....but if I try to do this further down the page, nothing will show
up.

So, now I'm expecting the Page_Load() method to do the work for me
(since it's on a codebehind file) but nothing is happening there
either. Does anyone know what I'm doing wrong? The basic problem is
shown below:

PaymentPage.aspx

<%@ Page language="c#" Codebehind="PaymentPage.aspx.cs"
AutoEventWireup="false"
Inherits="Webpay.NET_CSharpASPSample.PaymentPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Webpay.NET Start Page</title>
<meta content="VJ#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="amount" style="Z-INDEX: 111; LEFT: 152px; POSITION:
absolute; TOP: 80px" runat="server" Font-Bold="True"></asp:label>
</form>
</body>
</html>

------------------------------

PaymentPage.aspx.cs

public class PaymentPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label amount;

private void Page_Load(object sender, System.EventArgs e)
{
this.amount.Text = Request.Form["totalcost"];
}
}

-----------------------------

Thanks in advance for your help.

Regards,
Nick.
 
D

David Wier

Generally, what you would do is to create a page level variable in your code
behind (outside any events), then, inside the Page_load event, you'd
populate it
string myVar;

then, inside the Page_Load -
myVar=request.querystring("totalcost");

Then, you can use myVar anywhere you'd like in your code, though
Response.write is not used anymore (generally, though it can be). You would
put a label wherever you need the data to show - then:
label1.text=myvar;

I've never tried to post an ASP form to an ASPX page, so I'm not exactly
sure what to encounter in that regards.
 
Y

Yuriy Solodkyy

Hi,

You have disabled firing of Page_Load by setting

AutoEventWireup="false" in the header of the ASPX file.

You should either enable AutoEventWireup or override OnLoad method.

-yuriy
 
G

Guest

Thanks for everyone's reply but I've tried everything and nothing's worked.
Setting the AutoEventWireup to be true doesn't help either. If I make a
change to the aspx file, I can at least see a change but nothing I seem to do
to the aspx.cs file is having any effect. I even tried setting the hidden
property of another label and that did nothing either.

Any other ideas?

Thanks again,
Nicko.
 
Y

Yuriy Solodkyy

Can you set a breakpoint in Page_Load and see what value is assigned to Text
property? Do you reach the breakpoint?
 
G

Guest

Yuriy Solodkyy said:
Can you set a breakpoint in Page_Load and see what value is assigned to Text
property? Do you reach the breakpoint?

I haven't tried that yet. I'll give it a go today and let you know.

Thanks,
Nick.
 
G

Guest

OK, that works when I'm running the project from the .csproj file - even the
changes I make in Page_Load() work!

But, what I'm doing is copying the .aspx and .aspx.cs files out of the
project's directory and pasting it into another site directory once the
project has been rebuilt. Would this be part of the problem? I'm a beginner
at this so I'm still trying to get a feel for the way ASP.NET works...

Thanks in advance,
Nick.
 
Y

Yuriy Solodkyy

In ASP.NET 1.0/1.1 if you create your web site with Visual Studio you need
to build the .asp.cs files with the Visual Studio and deploy created assemblies
(DLL files) as well to the destination server.

You may try to add SRC attributes to your ASPX files to allow dynamic compilation
at your target location and avoid deploying DLLS. See: http://support.microsoft.com/kb/312311

However, as you don't get error message about not existing page base classes
it seems that you have already copied these assemblies to the target server.
When you copy your aspx and .aspx.cs target server just uses the older version
of already compiled .aspx.cs.

Try adding src attribute to @Page directive and see if it works or you get
error message.

-yuriy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top