百度空间 | 百度首页 
 
查看文章
 
关于.net中获取用户控件的值的问题
2008-10-15 13:21

假设有一用户控件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名获取其值的

下面这个不错:

expose a public property in depart.ascx:

public string SelectedValue
{
get { return DropDownList1.SelectedValue;}
}

or if you are lazy, try

DropDownList ddl = (DropDownList)YourUserControlID.FindControl("YourDropDownListID");
string s = ddl.SelectedValue;


类别:asp.net 知识 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu