代码改变世界

js获取服务器值以及服务器获取客户端值

2013-04-05 12:03  愿心平静面对  阅读(300)  评论(0编辑  收藏  举报

1.Label  

var text= document.getElementById(("<%=this.Label1.ClientID%>").innerText;

2.TextBox

var text= document.getElementById("<%=this.TextBox1.ClientID%>").value

3.DropDownList

var ddlvalue = document.getElementById('ctl00_Contentplaceholder3_ddlFolws').value

4.RadioButtonList

        var value = "";

        var Result = document.getElementsByName('ctl00$Contentplaceholder3$rblResult');
        for (var i = 0; i < Result.length; i++) {
            if (Result.item(i).checked) {
                value = Result.item(i).value;
            }
        }

服务器获取客户端值

<input type="text" name="test" />

方法1:Response.Write(Request.Form[test].toString())

方法2:System.Collections.Specialized.NameValueCollection nc = new System.Collections.Specialized.NameValueCollection(Request.Form);
           Response.Write(nc.GetValues("test")[0].ToString());