繁体   English   中英

为什么此事件异步触发?

[英]Why does this event fire asynchronously?

我有以下代码可以防止同时检查两个相对的无线电按钮:

RadioButton rbUSCitizenOrPermResY = null;
RadioButton rbUSCitizenOrPermResN = null;

. . .

rbUSCitizenOrPermResY = new RadioButton
{
    CssClass = "finaff-webform-field-input"
}; // doesn't allow assignment to CheckedChanged above
rbUSCitizenOrPermResY.CheckedChanged += new EventHandler(rbUSCitizenOrPermResY_Changed);

. . .

private void rbUSCitizenOrPermResY_Changed(object sender, EventArgs e)
{ 
    if (rbUSCitizenOrPermResN.Checked)
    {
        rbUSCitizenOrPermResN.Checked = false;
    }
}

因此,如果选中“是”单选按钮,则选中“否”单选按钮则取消选中“否”单选按钮。

据说。

实际上,此事件处理程序输入的,但单击单选按钮时不会输入。 而是在我单击“保存”按钮后触发。 这是一个异步事件处理程序,它会在需要时立即唤醒吗? 如果是这样,我如何才能“拉直并向右飞” /“整形或装运”?

我花了一些时间弄清楚您要描述的内容,因为我习惯于考虑这种东西,而不是服务器端。 但是由于您正在服务器端,所以我认为您需要为单选按钮引入某种分组构造。 我只是尝试了一个示例应用程序,其中使用了一个包含ListItems的RadioButtonList(直觉上,它们不称为Radiobuttons)。 但是,使用RadioButtonList对其进行分组,它们可以在客户端正确运行,即它们是互斥的。 单击一个取消选择另一个。 这是我使用的标记(这适合您的情况吗?):

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:listItem ID="rad1" runat="server"></asp:listItem>
    <asp:listItem ID="rad2" runat="server"></asp:listItem>
</asp:RadioButtonList>

listitem控件在设计器文件中转换为System.Web.UI.WebControls.ListItem

顺便说一句,我在Visual Studio中将其作为Web窗体应用程序进行了模拟。 我没有安装任何Sharepoint东西,但我认为原理是相同的(我希望如此)。

生成的HTML最终看起来像这样:

<table id="MainContent_RadioButtonList1">
    <tr>
        <td><span ID="rad1"><input id="MainContent_RadioButtonList1_0" type="radio" name="ctl00$MainContent$RadioButtonList1" value="" /></span></td>
    </tr>
    <tr>
         <td><span ID="rad2"><input id="MainContent_RadioButtonList1_1" type="radio" name="ctl00$MainContent$RadioButtonList1" value="" /></span></td>
    </tr>
</table>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM