[英]I can't figure out why my textbox isn't firing my OnClick c# function in asp.net
[英]why can't asp.net find my textbox?
我試圖將更多字段添加到CreateUserWizardStep
,這是我添加的內容:
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table border="0">
<tr>
<td align="right">
<asp:Label ID="NickNameLabel" runat="server" AssociatedControlID="NickName">Nick Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="NickName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="NickName"
ErrorMessage="Nick Name is required." ToolTip="Nick Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<%-- The default code is left unchanged, but not shown here --%>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
然后我試圖引用這樣的對象
protected void NewUserWizard_CreatedUser(object sender, EventArgs e)
{
CreateUserWizardStep step = NewUserWizard.FindControl("CreateUserWizardStep1") as CreateUserWizardStep;
TextBox nickName = step.FindControl("NickName") as TextBox;
// insert additional information to the database
}
問題是,我為nickName
獲取了null。 我是否使用了FindControl("")
錯誤?
您可能要使用遞歸查找控制功能,例如: http : //stevesmithblog.com/blog/recursive-findcontrol/
在當前命名容器中搜索指定的服務器控件。
即,它僅檢查當前容器的直接子代。
您可以使用Controls
屬性返回step
所有子step
:
ControlCollection children = step.Controls;
並在此尋找您的文本框。
我自己不知道控件,但是CreateUserWizardStep1.NickNameLabel不起作用嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.