【发布时间】:2011-04-06 20:41:28
【问题描述】:
我的组件(ascx):
这个组件是我页面的一部分,和他一起,我打开一个新页面(下一个代码)。
public void LoadSeller(string name, string id)
{
this.txtSeller.Text = name;
this.hdnSellerID.Value = id;
}
我的弹出窗口(aspx):
使用此代码,我进行了一些搜索并在 GridView 上选择了一项,将其发送回我的 ascx。
protected void btnSave_Click(object sender, EventArgs e)
{
Components.BasicData basicData= new Components.BasicData();
Button save = (Button)sender;
basicData.LoadSeller("TEST", save.CommandArgument);
}
回发有效,我收到了正确的数据(我检查了我的调试)。但是 txt 和 hidden 都是空的(就像它们没有加载一样),它们在没有我的弹出窗口的情况下工作,但我需要我的弹出窗口。
有什么想法吗?
PS:我的 viewState 是 UP。
我调试了我的整个代码,它停在了
this.txtSeller.Text = name;
LoadSeller 的第一行。这表示“this.txtSeller”为空,我不知道为什么。我检查了我的 .designer.cs 并声明了 this.txtSeller。 (如果我不尝试从其他页面加载,它也可以工作)
Obs:我想知道我的代码是否会以某种方式破坏我其他页面上的负载(或类似的东西)。
感谢您的帮助^.^
编辑:
我的结构是这样的:
页面
Control1
Control2
**Open pop up**
Control3
弹出窗口
Search
Gridview with buttons
gridview 中的按钮
Goes to my second code "my pop up (aspx):"
Close pop up
在我的 Control2 中,我有我的第一个代码“我的组件(ascx):”
字幕:Control == userControl
面包屑导航:
- 解决方案
- 组件(文件夹)
- BasicData.ascx
- PopUp.aspx
- 组件(文件夹)
【问题讨论】:
-
什么是
Components.BasicData?如果它是 UserControl,如果您想动态添加它,则应该使用Page.LoadControl("BasicData.ascx")加载它,或者如果它已经在页面上,则直接引用它。 -
感谢蒂姆,您的回答 ^.^ 我尝试使用
Components.BasicData,在此行之前使用Components.BasicData basicData= new Components.BasicData();,但这不起作用。
标签: c# asp.net nullreferenceexception