日期:2014-05-18  浏览次数:20335 次

asp.net自定义控件问题
我这有个用户自定义控件ascx,在控件中有些textbox,
我想运行一个.cs文件,从页面中所显示的这个自定义控件中输入一些值,然后把它插入到数据库中,我在.cs文件中无法用ascxID.textbox来提取值,找不到自定义控件的textbox字段,而且也不能在aspx页面中输入,这是为何??我应该怎样才能获得自定义控件中的textbox的值呢??

------解决方案--------------------
先到用户控件里面写个方法取出textbox的值
再找到这个用户控件
UserControl dl = (UserControl)(e.Item.FindControl("UserControl1"))
再用dl去调用那个方法
string str = dl.方法();
------解决方案--------------------
ascx.cs 中
写一方法:
public string GetValue()

return textbox.Text;
}


调用时用 ascxID.GetValue();

注:由于该ascx中包含 runat=server的TextBox.
所以该ascx必须放在有runat=server标记的form标签内。