tags:

views:

4763

answers:

2

Here is an extract of HTML from within a standard HTML page:

<form name="login_form" action="http://localhost/BOB.WebPortal/LoginForm.aspx" method="post>
     <div id="content_logins">

      <div id="spacer_ie" style="width:990px; height:7px; border:none; float:left"></div>
      <div style="width:255px; height:22px; border:none; float:left"></div>
         <div style="width:172px; border:none; float:left; vertical-align:bottom">
           <input type="text" name="uname" id="uname" size="13" /></div>
          <div style="width:110px; border:none; float:left">
           <input type="password" name="pword" id="pword" size="13" /></div>
          <div style="width:140px; height:22px; border:none; margin-top:-2px; float:left">
           <!--input class="btbgfix" type="image" src="images/submit.png" alt="Submit" value="Login"-->
       <input name="submit" id="loginButton" class="btbgfix" type="image" src="images/submit.png" alt="Submit" value="Login"></div>
      <div style="width:320px; height:22px border:none; float:left">
       <img name="login" src="x.gif" id="alogin" usemap="#m_login" border="0" width="320" height="22" />
       <map name="m_login" id="m_login">
        <area shape="rect" coords="0,0,681,22" href="https://www.aetmyportfolio.com.au" target="_blank" alt="Go to AET My Portfolio" />
       </map>
      </div>  

           </div> 
    </form>

My problem is that I am trying to retrieve the post value uname and pword using Request.Form from within the Page_Load event of the C# codebehind file in my ASP.Net application. However I find that Request.Form is empty. However if I use Request.Params then I can access the values as they are being passed as query string values in the URL.

Am I doing something wrong in my html?

+6  A: 

Assuming that's a direct copy-paste from your HTML, you're missing a closing quote on the end of "post".

Ch00k
You are right. I couldn't see that one for looking. Thanks.
daveywc
Wow, did that fix it? Crazy
Andy White
+2  A: 

Since you are working with a standard HTML page for your login control, it does not seem like the runat="server" is going to solve all of your problems. Here is a quick sample of how I replicated your solution. It seems to pick up the values correctly.

Login Page

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
    <title></title>
</head>
<body>
    <form name="login_form" action="Default.aspx" method="post">
    <div id="content_logins">
            user:<input type="text" name="uname" id="uname" size="13" /><br />
            pass:<input type="password" name="pword" id="pword" size="13" /><br />
            <input name="submit" id="loginButton" type="submit" alt="Submit" value="Login">
    </div>
    </form>
</body>
</html>

Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text = Request.Params["uname"].ToString();
        this.Label2.Text = Request.Params["pword"].ToString();
    }
}
RSolberg