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

在.cs代码文件中无法识别控件!郁闷,该如何处理

2012-03-06 
在.cs代码文件中无法识别控件!郁闷小弟做了一个注册网页,用的的VS2005内容如下:%@ Page LanguageC# Au

在.cs代码文件中无法识别控件!郁闷
小弟做了一个注册网页,用的的VS2005 内容如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login_Person.aspx.cs" Inherits="Login_Person" %>

<!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 id="Head1" runat="server">
  <title>个人用户注册</title>
</head>
<body>
  <form id="form1" runat="server">
  <div runat = "server">
  <center>
  <table width = "750px">
  <tr> <td style=" width:150px;height:82px; font-size: 20pt; font-family: 幼圆;">
  水院信息港</td>
  <td style="height: 82px"> </td>
  </tr>
  </table>
  <table width = "750px">
  <tr><td style="height:25px">
  &nbsp;&nbsp;</td></tr>
  </table>
  <table width = "750px" style ="height :400px">
  <tr>
  <td style="width :200px; height: 390px; text-align: center;">
  </td>
  <td style="vertical-align: middle; text-align: center">
  <table style="width: 440px; height: 318px" >
  <tr>
  <td colspan = "2">
  个人新用户注册</td> 
  </tr>
  <tr>
  <td style="width: 140px" >
  用户名:</td>
  <td style="width: 300px" >
  <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
  </td> 
  </tr>
  <tr>
  <td style="width: 140px">
  密码:</td>
  <td style="width: 300px">
  <asp:TextBox ID="Password" TextMode = "Password" runat ="server" Width="150px"></asp:TextBox> 
  </td>
  </tr>
  <tr>
  <td style="width: 140px">
  确认密码:</td>
  <td style="width: 300px">
  <asp:TextBox ID = "ConfirmPassword" TextMode = "Password" runat = "server" Width="150px"></asp:TextBox>
  </td> 
  </tr>
  <tr>
  <td style="width: 140px">
  性别:</td>
  <td style="width: 300px">
  <asp:RadioButton ID = "Male" runat = "server" Text = "男" GroupName = "Sex" Checked = "true" />
  <asp:RadioButton ID = "Famale" runat = "server" Text = "女" GroupName = "Sex" Checked = "false" />
  </td>
  </tr>
  <tr>
  <td style="width: 140px">
  电子邮件:</td>


  <td style="width: 300px">
  <asp:TextBox ID = "Email" runat = "server" ></asp:TextBox>
  </td> 
  </tr>
  <tr>
  <td style="width: 140px">
  联系电话:</td>
  <td style="width: 300px">
  <asp:TextBox ID = "Phone" runat = "server"></asp:TextBox>
  </td>
  </tr>
  <tr>
  <td style="width: 140px; height: 30px;">
  安全提示问题:</td>
  <td style="width: 300px; height: 30px;">
  <asp:TextBox ID = "Question" runat = "server"></asp:TextBox>
  </td>
  </tr> 
  <tr>
  <td style="width: 140px; height: 31px;">
  安全答案:</td>
  <td style="width: 300px; height: 31px;">
  <asp:TextBox ID = "Answer" runat = "server"></asp:TextBox>
  </td>
  </tr> 
  <tr>
  <td colspan = "2" style="height: 25px">
  &nbsp;<input type ="submit" value = "提交" runat = "server" id="Submit1" onserverclick="Submit1_ServerClick" />
  <input type = "reset" value = "重置" runat = "server" /> 
  </td>
  </tr>  
  </table>
  </td> 
  </tr>
  </table>
  <table width = "750px">
  <tr>
  <td style="height: 55px"></td>
  </tr>
  </table>
  </center>
  </div>
  </form>
</body>
</html>


但在“提交”按钮的事件写代码,往数据库中写东西,最后运行却提示:当前上下文不存在诸如:UserName,Password...也不知道是怎么回事,请教各位大虾!不胜感激!在线等!

[解决办法]
是表示层的数据没有传递到数据层,可能是参数设置问题,还有可能是接口问题,有没有引用这个方法。你先看一下.cs文件吧
[解决办法]
曾经遇到过这样的问题,原因还是CodeFile="Login_Person.aspx.cs" Inherits="Login_Person" 没有关联上,去看下".cs文件里的类名是否跟aspx的Inherits一样,或者干脆把Inherits="Login_Person删除。

我当时遇到的情况是我复制了一份文件,也就是文件夹下有2个Login_Person.aspx和Login_Person.aspx.cs,是因我在修改是复制了一份,另一分叫复件Login_Person.aspx和复件Login_Person.aspx.cs,虽然文件名不一样,但是两个文件的Inherits一样,里面内容一样,所以在vs2005里编译运行时候可以,但写代码的时候提示找不到页面里的元素,把后者删除就可以了!不知道你有没有这种情况。

其他问题就不知道了,知道了在来回!

热点排行