在后台我是这样添加控件的
 public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Response.Write(quyu_shiyonglv());
            }
                   }       public string quyu_shiyonglv()
        {
            string strBody = null;
             strBody += "<ul>";
            strBody += " <li>";
            strBody += " <input type='checkbox' id='1' /><a href='http://baidu.com'>1</a><select id='ass'runat='server'><option value='1'>21a</option>";
            strBody += "<option value='1'>22a</option></select>";
            strBody += " <ul>";
            strBody += "  <li>4";
            strBody += " <ul>";
            strBody += "  <li>5 </li>";
            strBody += " </ul>";
            strBody += " </li>";
            strBody += "  </ul>";
            strBody += " </li>";
            strBody += "</ul>";
            strBody += " ---------------------------------------------- ";
            return strBody;
       }
   }然后我添加个后台事件
 protected void btn_Click(object sender, EventArgs e)
        {
           这里怎么获取上面控件的值;
        }

解决方案 »

  1.   

    你是想页面加载的时候显示出来内容 还是Click事件的时候显示出来?
      

  2.   

    你必须使用
    <select name='ass'>Request.Params.Get("ass")
    获得
      

  3.   

    我是想页面加载后,Btn_Click事件获取控件值
      

  4.   

    另外,Response.Write(quyu_shiyonglv());
    也是不行的,这样不能放在form里面了,
    你需要放一个Literal控件或者使用<%=%>插入到form内
      

  5.   

    例子
    <%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">  protected void Page_Load(object sender, EventArgs e)
      {
        if (!IsPostBack)
        {
          Literal1.Text = quyu_shiyonglv();
        }
      }  public string quyu_shiyonglv()
      {
        string strBody = null;
        strBody += "<ul>";
        strBody += " <li>";
        strBody += " <input type='checkbox' id='1' /><a href='http://baidu.com'>1</a><select name='ass'><option value='1'>21a</option>";
        strBody += "<option value='2'>22a</option></select>";
        strBody += " <ul>";
        strBody += " <li>4";
        strBody += " <ul>";
        strBody += " <li>5 </li>";
        strBody += " </ul>";
        strBody += " </li>";
        strBody += " </ul>";
        strBody += " </li>";
        strBody += "</ul>";
        strBody += " ---------------------------------------------- ";
        return strBody;
      }  protected void Button1_Click(object sender, EventArgs e)
      {
        Response.Write(Request.Params.Get("ass"));
      }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title></title>
    </head>
    <body>
      <form runat="server" id="form1">
      
      <asp:Literal ID="Literal1" runat="server"></asp:Literal>
      <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
      </form>
    </body>
    </html>
      

  6.   

    public string quyu_shiyonglv()
      {
      string strBody = null;
      strBody += "<ul>";
      strBody += " <li>";
      strBody += " <input type='checkbox' id='1' /><a href='http://baidu.com'>1</a><select id='ass'runat='server'><option value='1'>21a</option>";
      strBody += "<option value='1'>22a</option></select>";
      strBody += " <ul>";
      strBody += " <li>4";
      strBody += " <ul>";
      strBody += " <li>5 </li>";
      strBody += " </ul>";
      strBody += " </li>";
      strBody += " </ul>";
      strBody += " </li>";
      strBody += "</ul>";
      strBody += " ---------------------------------------------- ";
      return strBody;
      }
      }你这段代码不许是在form表单里面还有你每个空间都要加一个name属性
    后台你可以通过request.form[name]来得到值。
      

  7.   

    写错字了是必须在form表单里面。