为什么不异步此事件火? [英] Why does this event fire asynchronously?

查看:111
本文介绍了为什么不异步此事件火?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从两个被检查得到这个code至prevent两个相反的无线电buttoms:

I've got this code to prevent two opposite radio buttoms from both being checked:

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;
    }
}

因此​​,如果是单选按钮被选中,它如果否单选按钮被选中取消选中否的单选按钮。

So, if the "Yes" radio button is checked, it unchecks the "No" radio button if the "No" radio button is checked.

据推测。

在实际上,这个事件处理程序的的输入,但不能点击的单选按钮时。相反,它以后触发,当我点击保存按钮。这是一个异步事件处理程序,只是醒来的时候感觉一样吗?如果是这样,我怎么能得到它的清理整顿和飞行的权利/形或运出?

In actuality, this event handler is entered, but not when the radio button is clicked. Rather, it fires later, after I click the "Save" button. Is this an asynchronous event handler, that just wakes up whenever it feels like it? If so, how can I get it to "straighten up and fly right"/"shape up or ship out"?

推荐答案

这是我花了一段时间来找出你所描述的,因为我已经习惯了思考这个东西客户端,而不是服务器端。但既然你是做服务器端,我认为你需要引入某种形式的分组构造为您的单选按钮。我只是想一个示例应用程序,我使用含有一个ListItems的RadioButtonList的(而unintuitively,他们并不被称为单选按钮)。但是使用在RadioButtonList到组他们,他们正确地表现在客户端侧,即,它们是唯一的。点击一项取消选择其他。下面是我用的标记(这并不适合您的方案?):

It's taken me a while to figure out what you are describing, because I'm used to thinking about this stuff client side, not server side. But since you are doing server side, I think you need to introduce some kind of grouping construct for your radio buttons. I just tried an example app where I used a RadioButtonList containing ListItems (rather unintuitively, they are not called Radiobuttons). But using the RadioButtonList to group them, they behave correctly on the client side, i.e. they are exclusive. Clicking on one unselects the other. Here is the markup I used (does this fit your scenario?):

<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的东西,但我觉得原则是相同的(我希望)。

Incidentally, I mocked this up as a Web Form application in Visual Studio. I don't have any Sharepoint stuff installed, but I think the principle is the same (I hope).

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

The generated HTML ended up looking like this:

<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>

这篇关于为什么不异步此事件火?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆