隐藏字段后面的代码不刷新
本文关键字:代码 刷新 字段 隐藏 | 更新日期: 2023-09-27 18:06:41
//问题刷新值代码隐藏文件动态创建一个复选框,aspx文件包含被调用的javascript当复选框被选中时,请参见下面的内容:
//javascriptfunction checkBoxClicked(sender)
{
var hdnfldVariable = document.getElementById('hcompare');
if (sender.checked == true) {
sCompareAuditVersion = sender.value;
}
document.getElementById('hcompare').value = sCompareAuditVersion;
}
//aspx文件我使用了一个隐藏的字段来传递到文件后面的代码,并使用'x'来初始化值//确保值改变
<form id="form1" runat="server">
<div class="lowSectionClass">
<asp:HiddenField id="hcompare" value="X" runat="server">
</asp:HiddenField>
//文件后面的代码动态构建复选框
public class Report : Page
{
protected HiddenField hcompare;
private string populateCalculations(int tabID, int programID, int participantID)
{
string str = "";
str = ((((str + "<br /><br /><center><table cellpadding='0' cellspacing='10'>" + "<tr class='HeadingCellText'>") + "<td>Audit Version</td>" + "<td></td>") + "<td>Calculation Set</td>" + "<td></td>") + "<td>Run Calcs/Print Report/Print CSB</td>" + "<td></td>") + "<td>Compare?</td>" + "</tr>";
DataTable infoList = new DataTable();
infoList = new ReportClass().GetInfoList(programID);
if (infoList.Rows.Count > 0)
{
for (int i = 0; i < infoList.Rows.Count; i++) // 1 = a audit, 2 = b audit, 3 = c audit.....
{
if ((i % 2) == 0) //audit 'a' = 0, audit 'b' = 1
{
str = string.Concat(new object[] { str, "<td>", infoList.Rows[i]["dtCalcDate"], "</td>" }) + "<td></td>";
str = string.Concat(new object[] { str, "<td><a href='"javascript:runCalcs('", programID, "','", infoList.Rows[i]["sAuditVersion"].ToString(), "');'">Run Calcs</a> | <a href='"javascript:setPrintVariables(", programID, ",", participantID, ",'",
infoList.Rows[i]["sAuditVersion"].ToString(), "');section_CallBack('build');'">Print Report</a> | <a href='"ReportViewer.aspx?ProgramID=", programID, "&ParticipantID=", participantID, "&AuditVersion=",
infoList.Rows[i]["sAuditVersion"].ToString(),"&CompareAuditVersion=", hcompare.Value,"&csb=1'" target='blank'>Print CSB</a></td>"
}) + "<td></td>";
// above is where the hidden field is assigned to be passes in as a parameters and the value is not being updated
// below is where the checkbox is created and assigned function 'checkBoxClicked(this)'
str = string.Concat(new object[] { str, "<td><input id='Checkbox", i, "' tabindex='", i, "' value='", infoList.Rows[i]["sAuditVersion"].ToString(), "' onclick='checkBoxClicked(this)' type='checkbox' /></td>" }) + "</tr>";
}
}
}
return (str + "</tfoot>" + "</table></center>");
}
}
为隐藏字段设置clientidmode = static
<form id="form1" runat="server">
<div class="lowSectionClass">
<asp:HiddenField id="hcompare" value="X" clientIdMode="static" runat="server">
</asp:HiddenField>
</div>
</form>