首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于Label控件无法显示内容的有关问题

2012-05-28 
关于Label控件无法显示内容的问题我添加了label控件和textbox控件,想实现一个很简单的程序,就是点击Button

关于Label控件无法显示内容的问题
我添加了label控件和textbox控件,想实现一个很简单的程序,就是点击Button按钮在label控件上显示textbox里输入的内容,可是label控件里却怎么也不显示。。。。求助大虾啊

C# code

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Label7.Text= TextBox1.Text;
  }
}

[/code]



[code=C#][/code]<%@ 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 ID="Label1" runat="server" Font-Size="X-Large" ForeColor="Blue" Height="47px"
  Style="z-index: 100; left: 264px; position: absolute; top: 7px" Text="个人信息注册"
  Width="191px"></asp:Label>
  <asp:Label ID="Label2" runat="server" Height="34px" Style="z-index: 101; left: 139px;
  position: absolute; top: 81px" Text="用户名" Width="78px"></asp:Label>
  <asp:Label ID="Label3" runat="server" Height="34px" Style="z-index: 102; left: 139px;
  position: absolute; top: 156px" Text="密码" Width="78px"></asp:Label>
  <asp:Label ID="Label4" runat="server" Height="34px" Style="z-index: 103; left: 139px;
  position: absolute; top: 236px" Text="出生日期" Width="78px"></asp:Label>
  <asp:Label ID="Label5" runat="server" Height="34px" Style="z-index: 104; left: 139px;
  position: absolute; top: 310px" Text="电话号码" Width="78px"></asp:Label>
  <asp:Label ID="Label6" runat="server" Height="34px" Style="z-index: 105; left: 139px;
  position: absolute; top: 382px" Text="e-mail" Width="78px"></asp:Label>
  <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 106; left: 275px; position: absolute;
  top: 90px"></asp:TextBox>
  <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 107; left: 275px; position: absolute;
  top: 165px" TextMode="Password"></asp:TextBox>
  <asp:TextBox ID="TextBox3" runat="server" Style="z-index: 108; left: 275px; position: absolute;
  top: 246px"></asp:TextBox>
  <asp:TextBox ID="TextBox4" runat="server" Style="z-index: 109; left: 275px; position: absolute;
  top: 320px"></asp:TextBox>


  <asp:TextBox ID="TextBox5" runat="server" Style="z-index: 110; left: 275px; position: absolute;
  top: 391px"></asp:TextBox>
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 111;
  left: 282px; position: absolute; top: 473px" Text="注册" />
  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
  ErrorMessage="*用户名不能为空" Style="z-index: 112; left: 485px; position: absolute;
  top: 91px"></asp:RequiredFieldValidator>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
  ErrorMessage="*密码不能为空" Style="z-index: 113; left: 485px; position: absolute;
  top: 166px"></asp:RequiredFieldValidator>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3"
  ErrorMessage="*出生日期不能为空" Style="z-index: 114; left: 485px; position: absolute;
  top: 251px"></asp:RequiredFieldValidator>
  <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox3"
  ErrorMessage="*出生日期格式19910306" Style="z-index: 115; left: 485px; position: absolute;
  top: 251px" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"></asp:RegularExpressionValidator>
  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox4"
  ErrorMessage="*号码格式80060086" Style="z-index: 116; left: 485px; position: absolute;
  top: 322px" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"></asp:RegularExpressionValidator>
  <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="TextBox5"
  ErrorMessage="*e-mail格式为266060" Style="z-index: 117; left: 485px; position: absolute;
  top: 393px" ValidationExpression="\d{6}"></asp:RegularExpressionValidator>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4"
  ErrorMessage="*号码不能为空" Style="z-index: 118; left: 485px; position: absolute;
  top: 322px"></asp:RequiredFieldValidator>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox5"
  ErrorMessage="*e-mail不能为空" Style="z-index: 119; left: 485px; position: absolute;
  top: 393px"></asp:RequiredFieldValidator>
  <asp:Label ID="Label7" runat="server" Height="377px" Style="z-index: 121; left: 704px;
  position: absolute; top: 34px" Text="您输入的信息如下:" Width="328px"></asp:Label>
   
  </div>
  </form>
</body>
</html>
[code=C#][/code]

[解决办法]
可能是你用了验证控件,页面上某些表单验证通不过,所以Click事件没有执行。
------解决方案--------------------


看看Visibel属性设置对了没有呢,或者有没有在哪个地方修改了
[解决办法]
验证控件的事情。也就是你所有的文本框都得符合后。click才能执行。错一个都不行。很大可能是号码格式那出问题了。要不你只留着textbox1的验证。其他的先注释然后试一下就知道了。
[解决办法]
RequiredFieldValidator 控件验证没有通过。

热点排行