A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 崔增阳 中级黑马   /  2014-1-17 16:52  /  1550 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 崔增阳 于 2014-1-20 13:18 编辑

c#代码里的txtName和txtRemark为什么拿不到值呢?

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>            
        </div>
    </form>
        <form action="Default2.aspx" method="POST">
            <input type="hidden" name="hiddenVierState" value="<%=txtViewStateValue %>"/>
            姓名:<input type="text" name="txtName" value="<%=txtName %>"/><br/>
            密码:<input type="text" name="txtRemark" value="<%=txtRemark %>"/><br/>
            <input type="submit" value="提交"/>
        </form>

</body>
</html>




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

public partial class Default2 : System.Web.UI.Page
{
    public string txtName;
    public string txtRemark;
    public string txtViewStateValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        txtName = Request.Form["txtName"];
        txtViewStateValue = txtName;
        txtRemark = Request["txtRemark"];
        if (Request["hiddenVierState"]!=null)
        {
            if (Request["txtName"]==(Request["hiddenVierState"]))
            {
                    Response.Write("没有改变");
            }
            else
            {
                Response.Write("改变了");
            }
        }
    }
}


评分

参与人数 1技术分 +1 收起 理由
卖火柴 + 1

查看全部评分

4 个回复

倒序浏览
runat="server"  好象忘写了吧,你的第二个表单没写,在后台看来普通html代码,不给他生成ViewState的隐藏状态值
回复 使用道具 举报
第二个表单没有写  runat="server"

HTML中的这种写法,  我没有记错的话,应该是从前台拿后台的值而不是从后台拿前台的值吧
回复 使用道具 举报
好像第二个表单没有写 runat="server"
回复 使用道具 举报
form 标签里没有加上 runat=“server”
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马