Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 26th, 2004, 06:34 PM
Registered User
 
Join Date: Jan 2004
Location: , NSW, Australia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dati
Default HowTo Pass Form data from Page1.aspx to Page2.aspx

Hi,

I am currently studying the book (Beginning ASP.NET using VB.NET: ISBN: 1861005040 (Published Year: 2001)).

I am stuck at the code pass from Page1.aspx to Page2.aspx, I think it could be todo with the ASP.NET Version. I am using Microsoft.NET Framework v1.1.4322.

I have try putting the runat="server" in the Form section, to get rid of the error, but the submit does not Work.

I know how to extract the data from the same page, but since I am start to learn ASP.NET that's why I want to know why this method of passing from page1 to page2 doesn't work.

Please see the following code.

Thanks in advance.

Regards Dat.

Code:
Page1.aspx
-------------------------------------------------
Code:
<html>
<head>
    <title>Datagrid Control example</title>
</head>
<body>
    <form action="Page2.aspx" method="post" <s>runat="server"</s>>
        <p>
            Enter Your Name: 
            <asp:TextBox id="TextBox1" runat="server" />
        </p>
        <p>
            <input type="submit" value="Submit" />
            <input type="reset" value="Reset" />
        </p>
    </form>
</body>
</html>
Page2.aspx
-------------------------------------------------
Code:
<%@ Page Language="VB" %>
<script runat="server">

    Sub Page_Load()
            Message1.text = Request.Form("TextBox1")
    End Sub
</script>
<html>
<head>
    <title>datacontrol response</title>
</head>
<body>
    <p>
        <asp:Label id="Message1" runat="server" />
    </p>
</body>
</html>
Error When running Page1.aspx
Server Error in '/5040' Application.
---------------------------------------------------------------------
Control 'TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server.



Corrected Code:
Page1.aspx

Code:
<script>
    Public Sub Button1_Click(sender As Object, e As System.EventArgs)
        Server.Transfer("Page2.aspx",True)
    End Sub
</script>
<html>
<head>
    <title>Datagrid Control example</title>
</head>
<body>
    <form runat="server">
        <p>
            Enter Your Name: 
            <asp:TextBox id="TextBox1" runat="server" />
        </p>
        <p>
            <asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </p>
    </form>
</body>
</html>

The red highlighted code are the new code.
  #2 (permalink)  
Old January 27th, 2004, 12:59 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

its wahat I now & guess if its wrong plz correct me.
First of all when u use <asp: tags it must be in runat=server [u]form</u>.
Second, when u have runat=server [u]form</u> with <asp: it'll couse the page to postback (self-submit)!

Always:),
Hovik Melkomian.
  #3 (permalink)  
Old January 27th, 2004, 01:20 AM
Registered User
 
Join Date: Jan 2004
Location: , NSW, Australia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dati
Default

Hi Hovik Melkomian,

The reason why the runat="server" attribute is not set on the form because asp.net "automatically" create the action attribute within the Page1.aspx which stop me from moving to another page (Page2.aspx).

I select View Source when Page1.aspx is loaded with <form runat="server"
Code:
<form name="_ctl0" method="post" action="Page1.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE" value="dDwxOTg4MTk0Mzc2O3Q8O2w8aTwxPjs++==" />
My Question is can this be done without specifying runat="server" in the form section, if not how to pass data from page1.aspx to page2.aspx?

Code:
<form action="Page2.aspx" method="Post">
     <asp:Textbox runat="server">
</form>
Thank your for your reply.

Regards Dat
  #4 (permalink)  
Old January 27th, 2004, 01:51 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I know, did I say something else?!

Always:),
Hovik Melkomian.
  #5 (permalink)  
Old January 27th, 2004, 02:57 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The book was originally written for ASP.NET 1.0. Early beta's of that product indicated that it was possible to submit data from 1 page to the next. However, this feature was dropped in the final release.

It is possible to send information from 1 page to another, it's just not as straight-forward as you'd want it to. Check out the following articles for more information:

http://authors.aspalliance.com/kenc/passval.aspx
http://msdn.microsoft.com/library/de...FormsPages.asp

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #6 (permalink)  
Old January 27th, 2004, 06:54 AM
Registered User
 
Join Date: Jan 2004
Location: , NSW, Australia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dati
Default

Thanks Imar,

That's the answers I was looking for, I was suspected the error could be due to the version of the ASP.NET that I am running.

Look like I have to buy a book that have code written for ASP.NET version 1.1

:D
Regards Dat.
  #7 (permalink)  
Old January 27th, 2004, 06:57 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hmmm, not sure what you mean with that. The feature was dropped when version 1.0 came out, so it's not available in ASP.NET 1.0 but also not in ASP.NET 1.1.

It seems that later versions (i.e. Whidbey) may again support passing info from page to page.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 


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
Pass values from Aspx page to Flash Muthunagai.A ASP.NET 1.0 and 1.1 Professional 0 April 25th, 2007 11:43 PM
Pass values from Aspx page to Flash Muthunagai.A Excel VBA 0 April 25th, 2007 11:37 PM



All times are GMT -4. The time now is 06:49 PM.


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