Javascript 使用asp.net C获取文本框值的步骤#

Javascript 使用asp.net C获取文本框值的步骤#,javascript,asp.net,Javascript,Asp.net,在下面的代码中,我有一个文本框和一个隐藏字段。我的目标是获取文本框值和隐藏字段。我可以获取隐藏字段值。但是我无法获取文本框值。请任何人帮助我解决这个问题。 代码隐藏: string strRegularExp = string.Empty; if (ListOfRegularExpression != null) { for (int iRow = 0; iRow &

在下面的代码中,我有一个文本框和一个隐藏字段。我的目标是获取文本框值和隐藏字段。我可以获取隐藏字段值。但是我无法获取文本框值。请任何人帮助我解决这个问题。 代码隐藏:

string strRegularExp = string.Empty;

                    if (ListOfRegularExpression != null)
                    {
                        for (int iRow = 0; iRow < ListOfRegularExpression.Count; iRow++)
                        {
                            strRegularExp += ListOfRegularExpression[iRow].ToString() + "~~";
                            hidRegExp.Value = strRegularExp;
                            if (iRow == ListOfRegularExpression.Count - 1)
                            {
                                strRegularExp = strRegularExp.TrimEnd("~~".ToCharArray());
                                txtField.Attributes.Add("onblur", "javascript:ValidateRegExp('" + txtField.Text + " ," + hidRegExp.Value + "');");//textbox value to get
                            }

                        }
                    }

                    hidRegExp.Value = strRegularExp;
                  //  txtField.Text = strRegularExp;
                    lbl.Text = "The value of the HiddenField control is " + hidRegExp.Value + "."; 
                }
string strRegularExp=string.Empty;
if(ListOfRegularExpression!=null)
{
for(int-iRow=0;iRow
代码:Js

function ValidateRegExp(txtInput) {
        //alert(txtInput);
        var mySplitInput = new Array();
        mySplitInput = txtInput.split(",");


       var hiddenValue = document.getElementById("<%=hidRegExp.ClientID%>").value;
        alert(txtInput);
        var mySplitResult = new Array();
        mySplitResult = RegExp.split("~~");

        for (i = 0; i < mySplitResult.length; i++) {
            //document.write("<br /> Array[" + i + " ]= " + mySplitResult[i]);
            var re = new RegExp(mySplitResult[i]);
            if (txtInput.match(re)) {
               // alert("Successful match");
            } else {
               // alert("No match");
            }

        }

    }
 <asp:TextBox ID="txtField" runat="server" ></asp:TextBox>
<asp:HiddenField ID="hidRegExp" runat="server" >
</asp:HiddenField >
函数ValidateRegExp(txtInput){
//警报(TXT输入);
var mysplitnput=新数组();
mySplitInput=txtInput.split(“,”);
var hiddenValue=document.getElementById(“”).value;
警报(TXT输入);
var mySplitResult=新数组();
mySplitResult=RegExp.split(“~~”);
对于(i=0;i数组[“+i+”]=”+mySplitResult[i]);
var re=新的RegExp(mySplitResult[i]);
if(txtInput.match(re)){
//警报(“成功匹配”);
}否则{
//警惕(“不匹配”);
}
}
}

您已经声明了两次变量
hiddenValue
Javascript在不停止程序的情况下公平地抛出错误,因此您的脚本无法工作

   var hiddenValue = document.getElementById(mySplitInput[1]);
    // alert(mySplitInput[1]);

   var hiddenValue = document.getElementById("<%=hidRegExp.ClientID%>").value;
var hiddenValue=document.getElementById(mySplitInput[1]);
//警报(mysplitnput[1]);
var hiddenValue=document.getElementById(“”).value;

如果不记得,您可以将其重命名为hiddenvalue1吗