类和方法看不到属性asp

时间:2019-02-20 10:15:49

标签: c# asp.net

我是一个初学者,为什么在我的类和方法中看不到属性(id,类按钮,表),在代码中添加什么?

    protected void Search_Click(object sender, EventArgs e)
    {
        SearchWordDocument searchword = new SearchWordDocument();
        searchword.GetDocumentLibrary();
        //See atribute SearchField
    }
    public class SearchWordDocument {
        //Create array document
        //Not see atribute SearchField
        public void GetDocumentLibrary()
        {
         //Not see atribute SearchField          }

1 个答案:

答案 0 :(得分:3)

SearchWordDocument类与ASP.NET页没有关系,因此您必须向其传递相关信息。

像这样:

protected void Search_Click(object sender, EventArgs e)
{
    SearchWordDocument searchword = new SearchWordDocument();

    var term = SearchField.Text;
    searchword.GetDocumentLibrary(term);
}

public class SearchWordDocument 
{   
    public void GetDocumentLibrary(string searchTerm)
    {
        // use searchTerm
    }
}