无法读取文本框ID名称 [英] unable to read textbox id name
本文介绍了无法读取文本框ID名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我的代码背后代码无法读取aspz页面上的文本框ID名称(错误-名称"txtPWD"在当前上下文中不存在):
< asp:UpdatePanel ID =" ="span> runat =" 服务器" < ContentTemplate >
< asp:Button ID =" runat 服务器" 文本 登录"
onclick btnLgin_Click" / >
< asp:Panel ID =" runat 服务器" 样式 显示:无;" < asp:登录 ID =" runat 服务器" RememberMeText 记住我." BackColor =" >
< LayoutTemplate >
< 表 =" 边框 =" cellpadding =" 1" 单元格间距 =" >
< 正文 >
< tr >
< td >
< 表 =" 0" cellpadding > 0" >
< 正文 >
< tr >
< td =" 2" align center" >
您尚未登录.< /td >
< /tr >
< tr >
< td =" 右" < asp:Label ID =" runat 服务器" AssociatedControlID 用户名" ">< /asp:标签 >
< /td >
< td >
< asp:TextBox ID =" runat 服务器" < >
< asp:RequiredFieldValidator ID =" runat 服务器" ControlToValidate 用户名
ErrorMessage =" 工具提示 =" ValidationGroup =" ctl07 $ Login1" < /asp:RequiredFieldValidator >
< /td >
< /tr >
< tr >
< td =" 右" < asp:Label ID =" runat 服务器" AssociatedControlID 密码" ">< /asp:标签 >
< /td >
< td >
< asp:TextBox ID =" runat 服务器" TextMode 密码" < /asp:TextBox >
< asp:RequiredFieldValidator ID =" runat 服务器" ControlToValidate 密码"
ErrorMessage =" 工具提示 =" ValidationGroup =" > * < /asp:RequiredFieldValidator >
< /td >
< /tr >
< tr >
背后的代码:
SqlConnection con = 新 SqlConnection(ConfigurationManager.ConnectionStrings [" dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = 新 SqlCommand(" ,同上);
cmd.Parameters.AddWithValue(" ,txtUserName.Text);
cmd.Parameters.AddWithValue(" ,txtPWD.Text);
非常感谢
解决方案
Login1" < > < /td > < /tr > < tr > < td =" 右" < asp:Label ID =" runat 服务器" AssociatedControlID 密码" ">< /asp:标签 > < /td > < td > < asp:TextBox ID =" runat 服务器" TextMode 密码" < /asp:TextBox > < asp:RequiredFieldValidator ID =" runat 服务器" ControlToValidate 密码" ErrorMessage =" 工具提示 =" ValidationGroup =" > * < /asp:RequiredFieldValidator > < /td > < /tr > < tr >
背后的代码:
SqlConnection con = 新 SqlConnection(ConfigurationManager.ConnectionStrings [" dbconnection"].ConnectionString); con.Open(); SqlCommand cmd = 新 SqlCommand(" ,同上); cmd.Parameters.AddWithValue(" ,txtUserName.Text); cmd.Parameters.AddWithValue(" ,txtPWD.Text);
非常感谢
更新您的Web表单designer.aspx.cs文件.
如何更新designer.aspx.cs:
1.从页面上删除(剪切)控件.
2.再次将其粘贴到相同位置.
3.检查designer.cs文件,其中已创建实例,例如:
/// < 摘要 > /// txtPWD控件. /// < /summary > /// < 备注 > /// 自动生成的字段. /// 修改从设计器文件到代码隐藏文件的移动字段声明. /// < /注释 > 受保护的 全局 :: System.Web.UI.WebControls.TextBox txtPWD;
hello,
My code behind code is unable to read textbox ids name on the aspz page (error - The name ''txtPWD'' does not exist in the current context):
<asp:UpdatePanel ID="TestLogin" runat="server">
<ContentTemplate>
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLgin_Click" />
<asp:Panel ID="LoginPopup" runat="server" Style="display: none;">
<asp:Login ID="Login2" runat="server" RememberMeText="Remember me." BackColor="White">
<LayoutTemplate>
<table style="border-collapse: collapse;" border="0" cellpadding="1" cellspacing="0">
<tbody>
<tr>
<td>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2" align="center">
You are not logged in.</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">UserName:</asp:Label>
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="ctl07$Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="txtPWD" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ctl07$Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
code behind:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password", con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
Many thanks
解决方案
Login1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label> </td> <td> <asp:TextBox ID="txtPWD" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ctl07
Login1">*</asp:RequiredFieldValidator> </td> </tr> <tr>
code behind:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password", con); cmd.Parameters.AddWithValue("@username", txtUserName.Text); cmd.Parameters.AddWithValue("@password", txtPWD.Text);
Many thanks
Update your web form designer.aspx.cs file.
How can you update designer.aspx.cs:
1. Remove (Cut) control from page.
2. Paste it again on same position.
3. check designer.cs file where instance has been created like:
/// <summary> /// txtPWD control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.TextBox txtPWD;
这篇关于无法读取文本框ID名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文