469,648 Members | 1,549 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

What am I doing wrong?

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.
Jun 13 '07 #1
8 1284
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
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.

Jun 13 '07 #2
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.
--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"Nicko." <Nicko.@discussions.microsoft.comwrote in message
news:EE**********************************@microsof t.com...
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.

Jun 13 '07 #3
"Nicko." <Nicko.@discussions.microsoft.comwrote in message
news:EE**********************************@microsof t.com...
AutoEventWireup="false"
AutoEventWireup="true"
--
http://www.markrae.net

Jun 13 '07 #4
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.
Jun 13 '07 #5
Can you set a breakpoint in Page_Load and see what value is assigned to Text
property? Do you reach the breakpoint?

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.

Jun 14 '07 #6
"Yuriy Solodkyy" wrote:
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.
Jun 14 '07 #7
"Yuriy Solodkyy" wrote:
>
Can you set a breakpoint in Page_Load and see what value is assigned to Text
property? Do you reach the breakpoint?
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.
Jun 15 '07 #8
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
>"Yuriy Solodkyy" wrote:
>>Can you set a breakpoint in Page_Load and see what value is assigned
to Text property? Do you reach the breakpoint?
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.

Jun 15 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

121 posts views Thread by typingcat | last post: by
46 posts views Thread by Keith K | last post: by
13 posts views Thread by Jason Huang | last post: by
16 posts views Thread by Ajay | last post: by
8 posts views Thread by watkinsdev | last post: by
reply views Thread by shapper | last post: by
10 posts views Thread by DavidSeck.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.