我是一个初学者,为什么在我的类和方法中没有可见的属性(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          }

最佳答案

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
    }
}

08-19 12:59