Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 26th, 2008, 05:06 PM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default textbox viewstate missing on postback

I'm an asp.net user and just came across a problem in an old classic asp page so I'm not familiar.
I'm dealing with a form that's being posted back to itself and all the forms inputs are lost. In the page load i can access them through the Request[] object.

The page looks something like the following:
<% Import statements %>
<html>
<head>
<some javascript/>
</head>
<C# script>
void page_load(object, sender)
{
   //checks form input and does some database stuff
}
</script>
<body>
<form name="reg" onsubmit="return checkForm()" action="contact-regform.aspx" method="post" style="margin: 0; padding: 0">
<input name="firstname" size="34" style="margin: 4px 0px; width: 90%" />
<...some more inputs>
</html>

I've tried adding runat="server" to the form and input.
I've tried changing the input to an asp:textbox
I've tried adding value='<%= Request["firstname"] %>
but no matter what I do, the input are always blank on postback!

Please help.

  #2 (permalink)  
Old August 26th, 2008, 06:55 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

HUH???

> just came across a problem in an old classic asp page

and then:

<C# script>
void page_load(object, sender)
{
   //checks form input and does some database stuff
}
</script>


C# doesn't work in "old classic asp". And even in ASP.NET, you can't code
    <C# script>
and have it mean anything at all.

So what are you talking about?
  #3 (permalink)  
Old August 26th, 2008, 07:01 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmmm this post had me doubting what I thought I knew also...

Wind is your friend
Matt
www.elitemarquees.com.au
  #4 (permalink)  
Old August 26th, 2008, 07:15 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Come to think of it, even this line is a dead giveaway:

<% Import statements %>

Not to mention this:
    action="contact-regform.aspx"

This ain't no ASP page. It's pretty clearly ASP.NET. In which case you shouldn't be using
    <%= Request["firstname"] %>
(though you could...just not normal ASP.NET practice).
  #5 (permalink)  
Old August 27th, 2008, 08:06 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, I guess I'm trying to make heads of it myself. It's running in a .NET 2.0 runtime, an aspx page, but there's no codebehind page and the page_load is running in a <script> tag. Yes, Old Pedant, it's in there and it gets executed on page_load.

It also has some embedded <% if (Request["foo"] != "bar"} { %> statements littered throughout the page which I've only ever seen in classic ASP.

All I'm trying to do is have the input boxes save state on postback, but I'm having a hell of a time getting it to work.
<%= Request[""] %> isn't even working. It works in the Page_load <script> embedded in the aspx page, but when the html is rendered it's blank.



  #6 (permalink)  
Old August 27th, 2008, 08:10 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If there was confusion, i didn't mean <C script> literally, I was just writing shorthand.
<script runat="server" language="c#">

  #7 (permalink)  
Old August 27th, 2008, 03:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

If this is a page that posts back to itself, then there's no reason to use Request["xxx"]. Just use the same kind of code you would on a code-behind page.

Yes, an "all-in-one" page is perfectly legal in ASP.NET.

Hmmm...let me see if I have one sitting around for demo purposes...

Well, I don't have one in C# and the one in VB.NET is pretty silly, but still... It does work and does show that you just work with form fields same as you do in code-behind.

Code:
<%@ Page Language="VB" AutoEventWireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox1" runat="server" />
    <% If Session("xyz") = "xyz" Then%>
    <script>alert("yowser");</script>
    <% End If  %>
    <% If Checkbox1.Checked Then Session("xyz") = "xyz" %>
    <p>
    <asp:Button ID="doSubmit" Text="Test!" runat=server />
    </p>
    </div>
    </form>
</body>
</html>


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with viewstate and postback hertendreef ASP.NET 2.0 Professional 1 May 31st, 2008 04:05 PM
Viewstate Wervis BOOK: ASP.NET Website Programming Problem-Design-Solution 0 November 30th, 2005 09:42 AM
Evaluating Textbox in Realtime without postback mahulda ASP.NET 1.0 and 1.1 Basics 5 March 10th, 2004 03:52 AM
Masked TextBox & formatting TextBox melvik C# 1 September 22nd, 2003 11:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.