vb.net - ContentPage 和 UpdatePanel vb.net 中的 FindControl
问题描述
被这个难住了,已经搜索了各种答案,没有一个能够解决。继续获取ctl00 is not declared due to protection level
ct100
如果我删除MasterPage 并从开始ContentPlaceHolder
但我得到空引用,不要得到错误?
还想看看 UpdatePanel 是否也在其中发挥作用?
还想知道为什么Handles TextBox4.TextChanged
需要在 MasterPage 中删除?
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="resetPassword.aspx.vb" Inherits="resetPass" title="reset PW" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<h2>Password Recovery</h2>
<div style="border-style: double; background-color: #E7E7E7; width: 375px;">
<div class="grayBox"
style="font-weight: bold; font-size: large; text-align: center;">
CHANGE / RESET PASSWORD</div>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
User Name:
<asp:TextBox ID="TextBox4" runat="server" AutoPostBack="true" OnTextChanged="TextBox4_TextChanged"></asp:TextBox>
<br />
<br />
Password Question:
<asp:Label ID="Label1" runat="server" Text="?" Font-Bold="True" Font-Size="14" ForeColor="Red"></asp:Label><br />
<div id="results" runat="server"></div>
<br />
Password Answer:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
New Password:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Change Password" />
<br />
<br />
<div style="font-size: large; text-align: center;"><asp:Label ID="Label2" runat="server" Text="" Text-Align="center"></asp:Label></div>
<br />
</contenttemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
</div>
</asp:Content>
VB:
Protected Sub TextBox4_TextChanged(sender As Object, e As System.EventArgs) 'Handles TextBox4.TextChanged
Dim ctl00 As MasterPage = TryCast(FindControl("ctl00"), MasterPage)
Dim MainContent As ContentPlaceHolder = TryCast(FindControl("MainContent"), ContentPlaceHolder)
Dim TB4 As TextBox = TryCast(ctl00.MainContent.FindControl("TextBox4"), TextBox)
Dim uName As String = TB4.Text
Dim u As MembershipUser = myProvider.GetUser(uName, True)
Dim L1 As Label = ctl00.MainContent.FindControl("Label1")
Try
If u Is Nothing Then
L1.Text = "No user found"
Else
L1.ForeColor = System.Drawing.Color.Green
L1.Text = u.PasswordQuestion
End If
Catch ex As Exception
'xxx
Finally
conn.Close()
End Try
End Sub
解决方案
从该页面的代码隐藏访问内容页面控件时,您无需通过母版页。
所以,而不是
Dim L1 As Label = ctl00.MainContent.FindControl("Label1")
L1.Text = "No user found"
您可以使用
Label1.Text = "No user found"
等等。
推荐阅读
- mysql - 如果存在,则更新 else 插入,在存储过程中使用游标仅返回 1 行
- database - Swagger 2.0 生成 aspnetcore 模型和 EF Core 数据库优先方法生成模型
- javascript - 过滤嵌套数组
- javascript - React Child 组件无法访问上下文 API
- java - 使用输入列表获取实体对象列表:Spring Data JPA - Hibernate
- reactjs - Next.js SSR 存储访问令牌而不使用 redux
- .net - 使用 DataContract 反序列化为枚举时如何优化 ServiceStack.Text 性能
- swift - 键入“[类]?” 没有成员“[变量]”
- typescript - 如何在 TypeScript 中获取枚举值的类型
- filemaker - FileMaker 16/17 中缺少 External() 函数