あなたの目的のためにjqueryを使うべきです:
<script>
$(document).ready(function () {
var Error = false;
$("#RadioButton1").click(function () {
$("#TextBox2").attr("disabled", "disabled");
$("#TextBox1").removeAttr("disabled");
});
$("#RadioButton2").click(function () {
$("#TextBox1").attr("disabled", "disabled");
$("#TextBox2").removeAttr("disabled");
});
$("#Button1").click(function () {
var TextBox1value = $("#TextBox1").val();
var TextBox2value = $("#TextBox2").val();
var TextBox1Disable = $("#TextBox1").attr("disabled");
var TextBox2Disable = $("#TextBox2").attr("disabled");
if ((TextBox1value == "") && TextBox1Disable != "disabled") {
$("#Label1").text("text can not be empty");
Error = true;
}
if ((TextBox2value == "") && TextBox2Disable != "disabled") {
$("#Label2").text("text can not be empty");
Error = true;
}
});
$("#form1").submit(function (e) {
if (Error) {
alert("there are Some validation error in your page...!");
e.preventDefault();
}
});
});
</script>
本体要素は次のとおりです。
<form id="form1" runat="server">
<div>
</div>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="g1" /><asp:TextBox ID="TextBox1" runat="server" Enabled="False"></asp:TextBox><asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
<br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="g1" /><asp:TextBox ID="TextBox2" runat="server" Enabled="False"></asp:TextBox><asp:Label ID="Label2" runat="server" ForeColor="Red"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>