【发布时间】:2012-01-11 23:32:15
【问题描述】:
基于在下拉列表中选择“其他”,我想将标签和文本框添加到 <p> 标记。我在<p> 标签中添加了runat=server。
Protected Sub deptDdl_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles deptDdl.SelectedIndexChanged
'If the user chooses other for the department type add
'a label and textbox to allow them to fill in a department not listed
If deptDdl.SelectedValue.ToString = "Other" Then
Dim deptLbl As Label = New Label
deptLbl.Text = "Enter the Department Name"
Dim deptTb As TextBox = New TextBox
deptTb.MaxLength = 20
Page.FindControl("m_ContentPlaceHolder1_deptPtag").Controls.AddAt(2, deptLbl)
Page.FindControl("m_ContentPlaceHolder1_deptPtag").Controls.AddAt(3, deptTb)
End If
End Sub
我不断收到未处理的异常,指出未将对象引用设置为对象的实例。
我错过了什么?
【问题讨论】:
-
提示:您不需要
As X = New X。你可以做As New X。以Dim deptLbl As New Label()为例。
标签: asp.net vb.net drop-down-menu