我正在开发一个得分表应用程序,我有一个带有单选按钮的转发器,当我检查一个收音机时,会弹出一个弹出窗口。它工作正常。但问题是每当我检查另一行中的下一个收音机时,我会得到重复的弹出窗口(一个用于新收音机,另一个用于前一个收音机。并且它发生在转发器的所有行上(如果我检查20个收音机)在20行中,它将同时显示20个弹出窗口。。我需要无线电一直保持检查,但因为Autopost每次都会触发它们后面的代码。
代码在转发器的PreRender事件下,但有人建议我把它从转发器中取出。 (顺便说一下PreRender和ItemDataBound事件有什么区别?)请帮助。
这是我的代码:
namespace GAPP
{
public partial class GRADE : System.Web.UI.Page
{
bool rdchk = false;
protected void Page_Load(object sender, EventArgs e)
{
//-----------to define an event handler for the RadioButton control inside a repeater----------
this.rptr1.ItemDataBound += new RepeaterItemEventHandler(rptr1_ItemDataBound);
if (IsPostBack)
{
for (int i = 0; i < this.rptr1.Items.Count; i++)
{
RadioButton RDB1 = rptr1.Items[i].FindControl("L1") as RadioButton;
RadioButton RDB2 = rptr1.Items[i].FindControl("L2") as RadioButton;
RadioButton RDB3 = rptr1.Items[i].FindControl("L3") as RadioButton;
RadioButton RDB4 = rptr1.Items[i].FindControl("L4") as RadioButton;
RadioButton RDB5 = rptr1.Items[i].FindControl("R1") as RadioButton;
RadioButton RDB6 = rptr1.Items[i].FindControl("R2") as RadioButton;
RadioButton RDB7 = rptr1.Items[i].FindControl("R3") as RadioButton;
RadioButton RDB8 = rptr1.Items[i].FindControl("R4") as RadioButton;
RDB1.AutoPostBack = true;
RDB1.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
RDB2.AutoPostBack = true;
RDB2.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB3.AutoPostBack = false;
RDB3.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB4.AutoPostBack = true;
RDB4.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB5.AutoPostBack = true;
RDB5.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
RDB6.AutoPostBack = true;
RDB6.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB7.AutoPostBack = false;
RDB7.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB8.AutoPostBack = true;
RDB8.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
}
}
}
//----------------------------end of define event-----------------------------------------
private void RDBX1_CheckedChanged(Object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
Button bsr1 = (Button)item.FindControl("btn_saveRep1");
Button bsr2 = (Button)item.FindControl("btn_saveRep2");
Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");
RadioButton l1 = (RadioButton)item.FindControl("L1");
RadioButton r1 = (RadioButton)item.FindControl("R1");
if (l1.Checked && rdchk == false)
{
bsr1.Visible = true;
bsr2.Visible = false;
bsr3.Visible = true;
bsr4.Visible = false;
mpex2.Show();
}
if (r1.Checked && rdchk == false)
{
bsr1.Visible = false;
bsr2.Visible = true;
bsr3.Visible = false;
bsr4.Visible = true;
mpex2.Show();
}
}
}
}
private void RDBX2_CheckedChanged(Object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
RadioButton l2 = (RadioButton)item.FindControl("L2");
if (l2.Checked) mpex1.Show();
RadioButton l4 = (RadioButton)item.FindControl("L4");
if (l4.Checked) mpex1.Show();
RadioButton r2 = (RadioButton)item.FindControl("R2");
if (r2.Checked) mpex1.Show();
RadioButton r4 = (RadioButton)item.FindControl("R4");
if (r4.Checked) mpex1.Show();
}
}
}
protected void rptr1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
protected void rptr1_PreRender(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
CheckBox chb = (CheckBox)item.FindControl("chkb_NO");
Label lbl1 = (Label)item.FindControl("lbl_dg_task");
Label lbl2 = (Label)item.FindControl("lbl_dg_seq");
Label lbl3 = (Label)item.FindControl("lbl_dg_repeat1");
Label lbl4 = (Label)item.FindControl("lbl_dg_final1");
RadioButton l1 = (RadioButton)item.FindControl("L1");
RadioButton l2 = (RadioButton)item.FindControl("L2");
RadioButton l3 = (RadioButton)item.FindControl("L3");
RadioButton l4 = (RadioButton)item.FindControl("L4");
RadioButton r1 = (RadioButton)item.FindControl("R1");
RadioButton r2 = (RadioButton)item.FindControl("R2");
RadioButton r3 = (RadioButton)item.FindControl("R3");
RadioButton r4 = (RadioButton)item.FindControl("R4");
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
Button bsr1 = (Button)item.FindControl("btn_saveRep1");
Button bsr2 = (Button)item.FindControl("btn_saveRep2");
Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");
//-----------------------------
if (chb.Checked == true)
{
l1.Enabled = false;
l2.Enabled = false;
l3.Enabled = false;
l4.Enabled = false;
r1.Enabled = false;
r2.Enabled = false;
r3.Enabled = false;
r4.Enabled = false;
l1.Checked = false;
l2.Checked = false;
l3.Checked = false;
l4.Checked = false;
r1.Checked = false;
r2.Checked = false;
r3.Checked = false;
r4.Checked = false;
lbl1.CssClass = "grayedout";
lbl2.CssClass = "grayedout";
}
else
{
l1.Enabled = true;
l2.Enabled = true;
l3.Enabled = true;
l4.Enabled = true;
r1.Enabled = true;
r2.Enabled = true;
r3.Enabled = true;
r4.Enabled = true;
lbl1.CssClass = "seq";
lbl2.CssClass = "task";
}
}
}
}
protected void rptr1_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "saveRep1")
{
DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat1");
Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
lbl3.Text = ddl1.SelectedItem.Text;
lbl4.Text = rbl1.SelectedItem.Text;
mpex2.Hide();
rdchk = true;
}
//------------------------------------------------------------
if (e.CommandName == "saveRep2")
{
DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat2");
Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final2");
RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
lbl3.Text = ddl1.SelectedItem.Text;
lbl4.Text = rbl1.SelectedItem.Text;
mpex2.Hide();
rdchk = true;
}
//------------------------------------------------------------
if (e.CommandName == "cnxlRepeat1")
{
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
l1.Checked = false;
mpex2.Hide();
}
//------------------------------------------------------------
if (e.CommandName == "cnxlRepeat2")
{
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
RadioButton r1 = (RadioButton)e.Item.FindControl("R1");
r1.Checked = false;
mpex2.Hide();
}
//------------------------------------------------------------
if (e.CommandName == "rdown")
{
ListBox lbx1 = (ListBox)e.Item.FindControl("ListBox1");
ListBox lbx2 = (ListBox)e.Item.FindControl("ListBox2");
if (lbx1.SelectedIndex != -1)
{
lbx2.Items.Add(lbx1.SelectedItem);
lbx1.Items.Remove(lbx1.SelectedItem);
lbx2.SelectedIndex = -1;
}
}
//------------------------------------------------------------
if (e.CommandName == "rup")
{
ListBox lbx3 = (ListBox)e.Item.FindControl("ListBox1");
ListBox lbx4 = (ListBox)e.Item.FindControl("ListBox2");
if (lbx4.SelectedIndex != -1)
{
lbx3.Items.Add(lbx4.SelectedItem);
lbx4.Items.Remove(lbx4.SelectedItem);
lbx3.SelectedIndex = -1;
}
}
//----------------------------------------------------------
if (e.CommandName == "ddl3Databound")
{
DropDownList ddlr1 = (DropDownList)e.Item.FindControl("DropDownList3");
ListBox lbx5 = (ListBox)e.Item.FindControl("ListBox1");
lbx5.DataBind();
}
//----------------------------------------------------------
if (e.CommandName == "plus")
{
Panel pnl1 = (Panel)e.Item.FindControl("pnlXtra");
TextBox txtb1 = (TextBox)e.Item.FindControl("txtb_comment");
ImageButton imgb1 = (ImageButton)e.Item.FindControl("imgBtn_xtraPlus");
ImageButton imgb2 = (ImageButton)e.Item.FindControl("imgBtn_xtraMin");
Label lblx1 = (Label)e.Item.FindControl("label2");
lblx1.Text = "after";
imgb1.Visible = false;
imgb2.Visible = true;
pnl1.Visible = true;
}
}
}
}
答案 0 :(得分:0)
PreRender和ItemDataBound事件有什么区别?
Prerender与您的页面相关(此处,控件也有prerender事件),而ItemDataBound与您的控件(如转发器,网格等)相关联。
在页面在客户端浏览器上呈现之前,在asp.net页面事件生命周期结束时调用Prerender。
ItemDataBound在Repeater / grid / datalist控件中的一个项目(foreach项目)受数据绑定但在页面上呈现之前发生
答案 1 :(得分:0)
解决了,我在检查收音机时创建了2个标签,我在if语句中使用了它们。 所以如果2个标签有文字,那么就不要显示弹出窗口。
非常感谢。