【发布时间】:2012-08-22 21:31:59
【问题描述】:
能否请您告诉我为什么以下代码不起作用,当调试器通过变量“strStatus”时,我收到错误消息。错误消息是:“对象引用未设置为对象的实例。”你能帮忙吗?谢谢-Yagya
protected void Button1_Click(object sender, EventArgs e)
{
if (Y0130_chkNew.Checked == true)
{
bool isChecked = true; // This is required for later retrieval.
string strAction = "Reporting";
string strFromRole = ddSelectRole.SelectedValue;
string TxtBoxID = myProject.getTextBox(strAction, strPath);
TextBox txtb = new TextBox();
txtb = (TextBox)Page.FindControl(TxtBoxID);
string strStatus = txtb.Text;
string ddID = myProject.getDropDown(strAction, strPath);
DropDownList ddLst = new DropDownList;
ddLst = (DropDownList)Page.FindControl(ddID);
string strForwardRole = ddLst.SelectedValue;
// Call the function now
my.updateXML(strFromRole, strAction, strStatus, strForwardRole, strPath);
}
}
【问题讨论】:
-
string TxtBoxID = myProject.getTextBox(strAction, strPath);是什么意思?你能展示那个方法吗?除此之外,Page.FindControl(TxtBoxID);返回 null 什么是您的异常的原因。FindControl不递归搜索控件,仅在给定的NamingContainer中搜索。
标签: asp.net