2 u012801613 u012801613 于 2013.11.11 16:25 提问

ASP中HTML控件,UI层获取文本值问题

asp:code

姓名
年龄
住址
备注

Cs:code

public partial class AddUserInfo : System.Web.UI.Page
{
UserInfoManager userinfoManager = new UserInfoManager();

    protected string userName;
    protected int age;
    protected string address;
    protected string remark;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.Form["txtUserName"] != null)
            {
                userName = Request.Form["txtUserName"];
            }
            if (Request.Form["txtUserAge"] != null)
            {
                age = Convert.ToInt32(Request.Form["txtUserAge"]);
            }
            if (Request.Form["txtAddress"] != null)
            {
                address = Request.Form["txtAddress"];
            }
            if (Request.Form["txtRemark"] != null)
            {
                remark = Request.Form["txtRemark"];
            }
            InsertInfo();
        }
    }
    public void InsertInfo()
    {
        UserInfo userinfo = new UserInfo();
        userinfo.UserName = userName;
        userinfo.UserAge = age;
        userinfo.UserAddress = address;
        userinfo.Remark = remark;
      int i=  userinfoManager.AddUserInfo(userinfo);
      if (i > 0)
      {
          Response.Write("添加成功!");
      }

    }

}

为什么获取不到htm控件文本值?是不是代码写的有问题?

Csdn user default icon
上传中...
上传图片
插入图片