因為需求希望使用radiobuttonlist控制上否上傳「預設檔案」或是「自傳檔案」
<asp:radiobuttonlist id="Upload" runat="server" RepeatLayout="Flow" RepeatColumns="2" RepeatDirection="Horizontal">
<ASP:LISTITEM Value="0" Selected="True"></ASP:LISTITEM>
<ASP:LISTITEM Value="1"></ASP:LISTITEM>
</asp:radiobuttonlist>
<INPUT id="cmdBrowse" type="file" size="40" name="cmdBrowse" runat="server">
<script language="javascript">
function ChangeUpload() {
rdlUpload = document.getElementById("Upload");
if (rdlUpload .checked) {
//有兩種方式可以控制或隱藏
//(1)disabled
document.getElementById("cmdBrowse").disabled = "disabled";
//(2)visible
document.getElementById("cmdBrowse").style.visibility = "hidden";
//清除INPUT type="file"的資料
ClearUpload();
} else {
//(1)取消visible
document.getElementById("cmdBrowse").style.visibility = "visible";
//(2)取消disabled
document.getElementById("cmdBrowse").disabled = "";
}
}
//清除INPUT type="file"的資料
function ClearUpload() {
var InputFile = document.getElementById("cmdBrowse");
InputFile.outerHTML = InputFile.outerHTML.replace(/value=\w/g, '');
}
</script>
c#的程式要加上onClick時觸法javascript的ChangeUpload()
rdlUpload.Attributes.Add("onClick", "javascript:ChangeUpload()")
0 意見: