下面是具有不同控件名称的类代码。 错误是
名称“ control_name”在当前上下文中不存在 每个控件名称。
注意:html控件具有runat=server
-属性。
namespace Wcd_Web_Dashboard.Classes
{
public class ClassA
{
public static void clear(string m_name)
{
if (m_name == "Register")
{
txt_Username.Value = string.Empty;
txt_user.Value = string.Empty;
txt_comment.Value = string.Empty;
ddl_district.SelectedIndex = 0;
ddl_tehsils.SelectedIndex = 0;
txt_FromDate.Value = string.Empty;
txt_ToDate.Value = string.Empty;
txt_RUserName.Value = string.Empty;
txt_RPassword.Value = string.Empty;
txt_RRePassword.Value = string.Empty;
}
if (m_name == "Login")
{
txt_Username.Value = string.Empty;
txt_Pass.Value = string.Empty;
}
}
}
}
答案 0 :(得分:0)
您的“当前上下文”是该方法是静态的。因此,这些控件都不存在(因为它们是实例级别的控件,而不是静态级别的控件)。从方法中删除static
修饰符,您的错误就会消失。