[英]ASP Radiobutton oncheckedchange not firing
I have a custom radiobutton below inside of a repeater and when a user clicks it, it is supposed to fire the code behind, however this is not firing at all. 我在转发器内部有一个自定义单选按钮,当用户点击它时,它应该触发后面的代码,但这根本不会触发。 I've placed a breakpoint at the beginning of the method and it isnt ever reached.
我在方法的开头放置了一个断点,它永远不会到达。 The only thing that does happen is a postback of the updatepanel
唯一确实发生的事情是updatepanel的回发
<EclipseUI:CustomRadioButton runat="server" ID="RadioButton_Select"
ClientIDMode="AutoID" ToolTip='<%# "id_" + Eval("FeaturePackId") %>' GroupName='<%# "id_" + Eval("FeaturePackId") %>'
OnCheckedChanged="RadioButton_Select_OnCheckedChanged" AutoPostBack="True"/>
The code behind is simply this, it takes the value of each checked radiobutton and places it in a hidden field for use later. 后面的代码就是这样,它取每个已检查的radiobutton的值并将其放在隐藏的字段中以供以后使用。
protected void RadioButton_Select_OnCheckedChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Clear();
foreach (RepeaterItem repeaterItem in Repeater_Select.Items)
{
CustomRadioButton radioButton = repeaterItem.FindControl("RadioButton_Select") as CustomRadioButton;
if (radioButton != null)
{
if (radioButton.Checked)
{
sb.Append(radioButton.GroupName.Substring(4));
}
else
{
sb.Replace(radioButton.GroupName.Substring(4), "");
}
}
}
HF_Feature.Value = sb.ToString();
}
My problem is that this doesnt fire at all. 我的问题是,这根本不会发生。
EDIT 编辑
My code is now as follows, and the item databound event is hit and so is the += assignment of the eventhandler to the radiobutton but clicking the radiobutton still doesnt hit my breakpoint in the OnCheckedChange of the radiobutton method: 我的代码现在如下,并且项目数据绑定事件被命中,因此将事件处理程序的+ =赋值给radiobutton但是单击radiobutton仍然没有在radiobutton方法的OnCheckedChange中击中我的断点:
protected void Page_Load(object sender, EventArgs e)
{
Repeater_Select.ItemDataBound += new RepeaterItemEventHandler(Repeater_Select_OnItemDataBound);
}
protected void Repeater_Select_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
CustomRadioButton customRbtn = (CustomRadioButton)e.Item.FindControl("RadioButton_Select");
customRbtn.CheckedChanged += new EventHandler(RadioButton_Select_OnCheckedChanged);
}
}
But it is still not working 但它仍然无法正常工作
in a repeater you will have to wire up the OnCheckedChanged events inside of the repeaters _ItemDataBound. 在转发器中,您必须连接转发器_ItemDataBound内的OnCheckedChanged事件。
protected void Page_Init(object sender, EventArgs e
{
myRepeater.ItemDataBound += new RepeaterItemEventHandler(myRepeater_ItemDataBound);
}
and then.. 接着..
private void myRepeater_ItemDataBound(object sender, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
ListItemType.AlternatingItem)
{
CustomRadioButton customRbtn = (CustomRadioButton)e.Item.FindControl("RadioButton_Select");
//Now you have an instance of your eclipse radio button so you can do what you want with it.
}
}
Have a looksy at this: OnCheckedChanged event handler of asp:checkbox does not fire when checkbox is unchecked at at way the "_ItemDataBound" is wired up. 看看这个: asp : onCheckedChanged事件处理程序在取消选中复选框时不会触发 “_ItemDataBound”连接的方式。
and this article may be a little closer to your problem if your using item template in the .aspx file. 如果你在.aspx文件中使用项目模板,这篇文章可能会更接近您的问题。 http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065/ASPNET-Tip-Use-the-ItemDataBound-Event-of-a-Repeater.htm
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065/ASPNET-Tip-Use-the-ItemDataBound-Event-of-a-Repeater.htm
Just try to setting CauseValidation="false" (besides Autopostback="true") 只是尝试设置CauseValidation =“false” (除了Autopostback =“true”)
<EclipseUI:CustomRadioButton runat="server" ID="RadioButton_Select" ClientIDMode="AutoID" ToolTip='<%# "id_" + Eval("FeaturePackId") %>' GroupName='<%# "id_" + Eval("FeaturePackId") %>' OnCheckedChanged="RadioButton_Select_OnCheckedChanged" AutoPostBack="True" CauseValidation="false"/>
It works... 有用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.