Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.

Reply With Quote
  #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?
Reply With Quote
  #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
Reply With Quote
  #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).
Reply With Quote
  #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.



Reply With Quote
  #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#">

Reply With Quote
  #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>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:45 PM.


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