在ascx文件中加入了一个下拉框 ddlCity 和两个<input type=text id=txtName>,为什么不能在.ascx页面上对txtName进行赋值?还需要设其它的地方吗?
另想再问一下,能不能直接在aspx页面上读取到ddlCity 的内容?
public string SelectedIndex
{
 get
 {
    return ddlCity.SelectedIndex.ToString();
 }
}
这样读取数据怎么不行?老是提示为Null值 ,ddlCity未定义?

解决方案 »

  1.   

    比如你的用户控件在页面上的id "usercontrol1"; 用户控件的类是 mycontrol
    你可以使用 ,
    mycontrol mc = (mycontrol)this.Findcontrol("usercontrol1");
    if( mc != null )
     return    mc.ddlCity.SelectedIndex
      

  2.   

    赋值没问题啊, 直接在ascx完成就可以, aspx用需要用Findcontrol找到你的用户控件的id号即可引用
      

  3.   

    在代码文件中手动添加声明,就能像使用本页其他的web服务器控件那样使用自定义的用户控件。例:private usercontrol uctl;
      

  4.   

    各位帮忙看看我这些代码有什么问题呢?
    ascx文件上
    <%@ Import Namespace="refresh"%>
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="modCityList.ascx.cs" Inherits="refresh.modCityList" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <script>
    function load(obj)
    {   var xx=obj.options.length;
     var m_CompanyID=obj.options[obj.selectedIndex].value;
     var m_companyName=obj.options[obj.selectedIndex].text;
    alert(m_CompanyID  + "  " +m_companyName);
    document.all.txtValue.value = "11";//问题所在
    document.all.TextBox1.value = "11";
    }    
    </script>
    <asp:DropDownList id="cboxCityList" runat="server" ></asp:DropDownList> <input type="text" id="txtValue" name="txtValue" runat="server" >
    <input type="text" id="txtText" name="txtText" runat="server">
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox
    cs后台:
    this.cboxCityList.Attributes.Add("onchange","load(this)");为什么我的txtValue的确不能赋值?!
      

  5.   

    少了
    <Form id=Form1 runat=server></Form>
      

  6.   

    TO: czhenq(挨饿中……) 
    我这个是在ascx中的,不应该有<Form id=Form1 runat=server></Form>
    吧!
    不然它会提示我:
     System.Web.HttpException: 一页只能有一个服务器端 Form 标记。我打算是把这个家伙放在另一个页面上的!
    各位大哥,教教我啊!