我使用C#background创建一个ASP.net在线应用程序。我也在使用AJAX MaskEditExtender。我是AJAX的新手,不懂Javascript。我需要做的是根据单选按钮的选择更改文本框AJAX掩码。 在这个例子中,他们选择薪水或每小时。我需要工资为“999,999”,小时工资为“99.99”。
<asp:TextBox ID="finalwage" runat="server" Width="80px">$</asp:TextBox>
<!-- Salary Mask -->
<asp:MaskedEditExtender
ID="MaskedEditExtender1"
runat="server"
TargetControlID="finalwage"
Mask="999,999"
MessageValidatorTip="true"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="None"
ErrorTooltipEnabled="true">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator
ID="MaskedEditValidator1"
runat="server"
ControlExtender="MaskedEditExtender1"
IsValidEmpty="true"
MinimumValue="0"
MaximumValueMessage="Must enter a number"
ControlToValidate="finalwage" >
</asp:MaskedEditValidator>
<!-- Hourly Mask -->
<asp:MaskedEditExtender
ID="MaskedEditExtender2"
runat="server"
TargetControlID="finalwage"
Mask="99.99"
MessageValidatorTip="true"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="None"
ErrorTooltipEnabled="true">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator
ID="MaskedEditValidator2"
runat="server"
ControlExtender="MaskedEditExtender1"
IsValidEmpty="true"
MinimumValue="0"
MaximumValueMessage="Must enter a number"
ControlToValidate="finalwage" >
</asp:MaskedEditValidator>
.......
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
AutoPostBack="true"
RepeatDirection="Horizontal"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Text="Hourly" Value="Hourly"
<asp:ListItem Text="Salary" Value="Salary" />
</asp:RadioButtonList>
下面是我认为可行的C#代码:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue = "Hourly")
{
MaskedEditExtender1.Mask = "99.99";
}
if (RadioButtonList1.SelectedValue == "Salary")
{
MaskedEditExtender1.Mask = "999,999";
}
}
答案 0 :(得分:1)
尝试将RadioButtonList1_SelectedIndexChanged代码移至Page_Init。我相信RadioButtonList1_SelectedIndexChanged在生命周期过程中为时已晚,无法更改掩码。