//问题刷新值 代码隐藏文件动态创建一个复选框,aspx文件包含调用的javascript 选中该复选框时,请参阅以下内容:
// java描述
function 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>
//代码隐藏文件动态构建chekbox
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>");
}
}
答案 0 :(得分:1)
为隐藏字段设置clientidmode = static
<form id="form1" runat="server">
<div class="lowSectionClass">
<asp:HiddenField id="hcompare" value="X" clientIdMode="static" runat="server">
</asp:HiddenField>
</div>
</form>