C#不能访问从同一类文本框 [英] c# cannot access textboxes from same class
问题描述
我有两个独立的问题;然而,由于它们是非常相似的,我会要求他们在一个张贴。
i have two separate questions; however, since they are very similar i will ask them in one posting.
什么是我不能从这里引用文本框的原因是什么?我创建了另一个文件在我的项目,并把
what is the reason i cannot reference the textboxes from here? i created another file in my project and put
namespace EnterData.DataEntry
{
public partial class WebForm1 : System.Web.UI.Page
{
,使其进入同一个命名空间和部分类作为网络表单。但我不能访问文本框!
to make it go into the same namespace and partial class as the webform. but i cannot access the textbox!
public partial class WebForm1 : System.Web.UI.Page
{
public class LOMDLL.Main_Lom_Form PopulateMainForm()
{
//populate class
LOMDLL.Main_Lom_Form TheForm = new LOMDLL.Main_Lom_Form();
try
{
TheForm.lom_number = lom_numberTextBox.Text.ToInt();
TheForm.identified_by = identified_byTextBox.Text;
TheForm.occurrence_date = occurrence_dateTextBox.Text.ToDateTime();
//TheForm.pre_contact = pre_contactTextBox.Text; //need to create this texdtbox
//TheForm.pre_practice_code = pre_practice_codeTextBox.Text; //create this
TheForm.report_by = report_byTextBox.Text;
TheForm.report_date = report_dateTextBox.Text.ToDateTime();
TheForm.section_c_comments = section_c_commentsTextBox.Text;
TheForm.section_c_issue_error_identified_by = section_c_issue_error_identified_byTextBox.Text;
TheForm.section_d_investigation = section_d_investigationTextBox.Text;
TheForm.section_e_corrective_action = section_e_corrective_actionTextBox.Text;
TheForm.section_f_comments = section_f_commentsTextBox.Text;
}
catch (Exception e)
{
}
我得到这个错误:
i get this error:
埃罗 R 20无法访问外部类型EnterData.DataEntry.WebForm1通过嵌套类型EnterData.DataEntry.WebForm1.LOMDLL'C的非静态成员:\\ Documents和Settings \\ agordon \\我的文档\\ Visual Studio 2008的\\项目\\ lomdb \\ EnterData \\ DataEntry \\ DAL.cs 68 38 EnterData code>
所有的文本框
什么是我不能从这里访问文本框的原因是什么?
what is the reason that i cannot access the textboxes from here?
推荐答案
您的意思是在这里筑巢类?如果您打算声明返回 Main_Lom_Form()
,试试这个方法:
Did you mean to nest classes here? If you intended to declare a method that returns a Main_Lom_Form()
, try this:
public LOMDLL.Main_Lom_Form PopulateMainForm()
如果您打算调用该方法对 WebForm1的
的成员名为 TheForm
,然后实例化的那个之外来电 PopulateMainForm
:
If you intended to call that method against a member of WebForm1
called TheForm
, then instantiate that outside of the call to PopulateMainForm
:
LOMDLL.Main_Lom_Form TheForm = new LOMDLL.Main_Lom_Form();
public void PopulateMainForm()
{
// snip
}
这篇关于C#不能访问从同一类文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!