所以我试图让用户输入点击按钮后显示的信息。我收到消息,但它不会显示输入到文本框中的值。我错过了什么?这是我的代码
private string _eyecolor;
public string Eyecolor
{
get { return _eyecolor; }
set
{
if (!string.IsNullOrEmpty(value))
{
_eyecolor = value.Substring(0, 1).ToUpper() + value.Substring(1);
}
else
{
_eyecolor = value;
}
}
}
public string getEyeColor()
{
return "You have " + _eyecolor + "eyes!!";
}
这是我的html代码:
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" ID="lbl_1" AssociatedControlID="txtb1" Text="what is your eyes color?" Autopostback="true" />
<asp:TextBox ID="txtb1" runat="server" />
<asp:Button ID="btn_submit" Text="Submit" runat="server" OnClick="subSubmit" />
<asp:Label runat="server" ID="lbl_output" />
</div>
</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 _Default : System.Web.UI.Page
{
Profile P = new Profile();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void subSubmit(object sender, EventArgs e)
{
lbl_output.Text=P.getMsg();
lbl_output.Text+=P.getEyeColor();
}
}