c#后台获取HTML页面的select的选值

来源:互联网 发布:淘宝联盟怎么找pid 编辑:程序博客网 时间:2024/05/16 07:56

第一种,当select的runat="server"不添加时

<div id="frm">

<asp:Label ID="lbcountry" Text="国家或地区:"></asp:Label>
  <select id="s1" name="s1" runat="server" onchange="Change2()">
        <option></option>
 </select>
<asp:Label ID="lbdays" Text="套餐天数:"></asp:Label>
    <select id="s2" name="s2" runat="server" onchange="Change3()">

          <option></option>

</select>

  <select id="s5"style="visibility: hidden;" name="s5">
           <option></option>
     </select>

 </div>

后台

using System.Collections.Specialized; 

NameValueCollection nc = new NameValueCollection(Request.Form);
            var country = nc.GetValues("s1")[0];
            var days = nc.GetValues("s2")[0];            
            string simid = nc.GetValues("s5")[0];

第二种,当select的runat="server"时

<div id="frm">
<asp:Label ID="lbcountry" runat="server" Text="国家或地区:"></asp:Label>
  <select id="s1" name="s1" runat="server" onchange="Change2()">
        <option></option>
 </select>
<asp:Label ID="lbdays" runat="server" Text="套餐天数:"></asp:Label>
    <select id="s2" name="s2" runat="server" onchange="Change3()">

          <option></option>

</select>

  <select id="s5" runat="server" style="visibility: hidden;" name="s5">
           <option></option>
     </select>
 </div>

后台

var country = Request["s1"];
            var days = Request["s2"];
            
            string simid = Request["s5"];

原创粉丝点击