通过JavaScript启用控件(单选按钮)
问题描述:
<head runat="server">
<title></title>
<script type="text/javascript">
function RadioClick() {
alert("Hi");
document.getElementById("FileUpload1").style.visibility = "visible";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="rbClderFormt" runat="server" GroupName="Format"/>
<asp:RadioButton ID="rdTableFormat" runat="server" GroupName="Format"/>
<asp:RadioButton ID="rdUploadFormat" runat="server" GroupName="Format"/>
<asp:FileUpload ID="FileUpload1" runat="server" Visible="false"/>
</div>
</form>
</body>
以上i代码。当我单击rdUploadFormat radioButton时,我必须更改FileUpload1的可见性。在后端我使用以下代码
The above is the code. I have to change the visibility of "FileUpload1" When I click the rdUploadFormat radioButton. In the back end I m using the following code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rdUploadFormat.Attributes.Add("OnClick", "return RadioClick()");
}
}
以上不起作用。我收到警告消息,但FileUpload不可见。
The above is not working. I am getting the alert message but the FileUpload is not visible.
答
删除Visible ='false'并将style ='display:none'添加到文件上传控件如下所述:
remove Visible='false' and add style='display:none' to your file upload control as mentioned below :
<asp:fileupload id="FileUpload1" runat="server" style="display: none" xmlns:asp="#unknown" />
并更新javascript方法,如下所示:
and update javascript method as shown below :
function RadioClick() {
alert("Hi");
document.getElementById("FileUpload1").style.display = "block";
}