p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   textbox viewstate missing on postback (http://p2p.wrox.com/showthread.php?t=70276)

JoshuaZ August 26th, 2008 05:06 PM

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 %>
<some javascript/>
<C# script>
void page_load(object, sender)
   //checks form input and does some database stuff
<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>

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.

Old Pedant August 26th, 2008 06:55 PM


> 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

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?

mat41 August 26th, 2008 07:01 PM

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

Wind is your friend

Old Pedant August 26th, 2008 07:15 PM

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

<% Import statements %>

Not to mention this:

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).

JoshuaZ August 27th, 2008 08:06 AM

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.

JoshuaZ August 27th, 2008 08:10 AM

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

Old Pedant August 27th, 2008 03:45 PM

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.


<%@ 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>
    <form id="form1" runat="server">
        <asp:CheckBox ID="CheckBox1" runat="server" />
    <% If Session("xyz") = "xyz" Then%>
    <% End If  %>
    <% If Checkbox1.Checked Then Session("xyz") = "xyz" %>
    <asp:Button ID="doSubmit" Text="Test!" runat=server />

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

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