ASP.Net AJAX的UpdatePanel不能与直放站和工作的RadioButtons [英] ASP.Net AJAX UpdatePanel not working with Repeater and RadioButtons

查看:101
本文介绍了ASP.Net AJAX的UpdatePanel不能与直放站和工作的RadioButtons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转发器,它包括在每个项目的无线电按钮,并更新面板内的整个事情站点。当我选择一个单选按钮,整个页面重新加载。为什么不只是更新更新面板。我已经减少这一个pretty简单的例子,以避免混乱。 code在这里...

ASPX ...

 < ASP:的ScriptManager ID =SM1=服务器/>
< ASP:的UpdatePanel ID =上一条=服务器的UpdateMode =条件>
    <&的ContentTemplate GT;
        < ASP:直放站=服务器ID =历史>
            <&ItemTemplate中GT;
                < ASP:单选=服务器ID =单选按钮的AutoPostBack =真正的组名=HistoryGroupOnCheckedChanged =RadioButton_CheckChanged/>< BR />
            < / ItemTemplate中>
        < / ASP:直放站>        < P>< ASP:文字=服务器ID =输出/>< / P>
    < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>

code ...

 公共部分类_Default:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        如果(!Page.IsPostBack)
        {
            清单< INT>名单=新名单,LT; INT>();
            的for(int i = 0; I< 20;我++)
                list.Add(ⅰ);
            history.DataSource = list.ToArray();
            history.DataBind();
        }
    }    保护无效RadioButton_CheckChanged(对象发件人,EventArgs的发送)
    {
        output.Text = DateTime.Now.ToString();
    }
}


解决方案

原来的解决方案是从单选按钮删除组名。当我删除此标签会以异步方式触发,只是更新面板。我实际上并不需要这个标签呢(由于已知的bug,其中组名不中继器上的单选按钮正常工作),因为我处理我的单击事件中的分组(即取消同一个名字的任何其他单选按钮在其他中继器项目)

I have a repeater which includes a radio button in each item, and the whole thing sites inside an update panel. When I select a radio button the whole page reloads. Why is it not just updating the update panel. I've reduced this to a pretty simple example to avoid clutter. Code here...

ASPX...

<asp:ScriptManager ID="SM1" runat="server" />
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Repeater runat="server" ID="history">
            <ItemTemplate>
                <asp:RadioButton runat="server" ID="radioButton" AutoPostBack="true" GroupName="HistoryGroup" OnCheckedChanged="RadioButton_CheckChanged" /><br />
            </ItemTemplate>
        </asp:Repeater>

        <p><asp:Literal runat="server" ID="output" /></p>
    </ContentTemplate>
</asp:UpdatePanel>

Code...

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            List<int> list = new List<int>();
            for (int i = 0; i < 20; i++)
                list.Add(i);
            history.DataSource = list.ToArray();
            history.DataBind();
        }
    }

    protected void RadioButton_CheckChanged(Object sender, EventArgs e)
    {
        output.Text = DateTime.Now.ToString();
    }
}

解决方案

Turns out the solution was to remove the GroupName from the RadioButton. When I remove this tag it fires asynchronously and just updates the panel. I don't actually need this tag anyway (due to the known bug where GroupName doesn't work on RadioButtons in Repeaters) as I handle the grouping within my click event (i.e. uncheck any other RadioButtons of the same name in other repeater items).

这篇关于ASP.Net AJAX的UpdatePanel不能与直放站和工作的RadioButtons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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