0
在下面的代碼中,我有一個隱藏字段,我必須將值存儲在隱藏字段中,並且我在隱藏字段中獲得了沒有值的空警報,但是我已經打印價值使用label.Pls幫助我解決問題。 代碼:從代碼隱藏到隱藏字段的值
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (FieldTypeInfo == FieldType.TextBox)
{
TblSearch.Visible = false;
TblDate.Visible = false;
tblDropd.Visible = false;
TblChk.Visible = false;
lblText.Text = FieldLabel;
txtreq.Enabled = this.IsMandatory;
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.ToString() + "');");
}
}
}
hidRegExp.Value = strRegularExp;
lbl.Text = "The value of the HiddenField control is " + hidRegExp.Value + ".";
}}}
JS:
function ValidateRegExp(txtInput) {
var hiddenValue = document.getElementById("<%=hidRegExp.ClientID%>").value;
alert("hiddenValue" + hiddenValue + ".");
var mySplitResult = new Array();
mySplitResult = hiddenValue.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:HiddenField ID="hidRegExp" runat="server" ClientIDMode="static" EnableViewState="true" >
</asp:HiddenField >
<asp:Label ID="lbl" runat="server"></asp:Label>
我能夠打印標籤中的值,然後當我在隱藏字段中看到沒有值時 – user3278874
所以當你看到頁面源時,你可以看到'value =「」'?如果您複製該頁面並刪除除HiddenField之外的所有代碼,該怎麼辦?我懷疑在代碼背後有一個事件會刪除隱藏輸入的值。 – HMR