您的位置:首页 > 其它

关于.net中获取用户控件的值的问题

2007-10-18 12:24 274 查看
假设有一用户控件a.ascx 里面有两个服务器控件<asp:TextBox runat="server" ID="txtUserName"></asp:TextBox>

<asp:Button ID="btnSubmit" runat="server" Text="提交"/>

如果在b.aspx中使用了a.ascx 怎么在b.aspx中获取控件txtUserName的Text值呢?

首先 在a.ascx中定义一个属性 public Strin UserName

{

get{return txtUserName.Text;}

}

可以直接在b.aspx中使用 userControl.UserName得到a.ascx中txtUserName的Text值

二..假设有一个select 标签 如<select runat="server" id="dpCity"></select>

假设城市列表由ajax动态生成 在后台cs中是无法直接取得dpCity的值

必须使用Request.Form[dpCity.UniqueID]得到dpCity的值 Request.Form使用的是客户端的name名获取其值的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: