当前位置: 代码迷 >> ASP.NET >> asp.net自定义控件有关问题
  详细解决方案

asp.net自定义控件有关问题

热度:9696   发布时间:2013-02-25 00:00:00.0
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标签内。
  相关解决方案