Solved

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

Posted on 2006-11-06
2
192 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

939 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

10 Experts available now in Live!

Get 1:1 Help Now