Solved

how come i cant access the request variables on an aspx page?

Posted on 2006-11-06
2
191 Views
Last Modified: 2010-04-16
i am trying to create a form and post a single value and read the value and its not working.
i have no idea why.

here is my page and codebehind:
########################################
page - title aspSUCKS.aspx
########################################
<%@ Page language="c#" Codebehind="aspSUCKS.aspx.cs" AutoEventWireup="false" Inherits="basketball.aspSUCKS" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>aspSUCKS</title>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server" action="aspSucks.aspx">
                  
                  <input type="text" id="userName">
                  <asp:Button id="Button1"  runat="server" Text="SUBMIT"></asp:Button>
            </form>
      </body>
</HTML>
######################################
codebehind page:
######################################
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace basketball
{
      /// <summary>
      /// Summary description for aspSUCKS.
      /// </summary>
      public class aspSUCKS : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Button Button1;
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.Button1.Click += new System.EventHandler(this.Button1_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void Button1_Click(object sender, System.EventArgs e)
            {
                  Response.Write("Here is the variable userName-->" + Request.Form["userName"]);
                  Response.End();
            }
      }
}
0
Comment
Question by:richardsimnett
2 Comments
 

Author Comment

by:richardsimnett
ID: 17882780
changed it from a <input type=text> to an <asp:TextBox
and it works fine.

points are still up for grabs if you can tell me why.

thanks.
0
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 125 total points
ID: 17884467
input type="text" is an HTML control. It will only post as part of the form if you give it a name attribute. When you use an ASP.NET server-side control, it renders to the browser with an appropriate name attribute worked out from the control's ID, so that posts automatically. Try your first one with a name as well as an ID and it should work.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now