如何检查是否已在页面加载上触发ddl.selectedindexchanged事件

时间:2014-03-27 18:42:53

标签: c# asp.net drop-down-menu panels

这是我的代码:在页面加载

protected void Page_Load(object sender, EventArgs e)
{

    //On first request
    if (!IsPostBack)
    {
        panel1.Visible = true;
        panel2.Visible = false;
        panel3.Visible = false;
    }
    //for subsequent postbacks
    else 
    {
        //If the enquiry is direct
        if ( Direct_Rdbtn.Checked)
        {
            panel1.Visible = false;
            panel2.Visible = false;
            panel3.Visible = true;

            //add default text value "D" for date dropdownlist of DOB
            if (DOB_Date_Ddl.Items.Count == 0)
            {
                ListItem li = new ListItem();
                li.Text = "D";
                DOB_Date_Ddl.Items.Add(li);
            }
        }
        //For all other sources of enquiries
        else 
        { 
     //in this if statement i actualy want to check for `selectedindexchange` event togther with `AllOthers_Rdbtn.Checked`
            if (AllOthers_Rdbtn.Checked )
            {
                panel1.Visible = false;
                panel2.Visible = false;
                panel3.Visible = true;

            }
            else if (AllOthers_Rdbtn.Checked)
            {
                panel1.Visible = false;
                panel2.Visible = true;
                panel3.Visible = false;
                LinkButton1.Enabled = false;
                LinkButton1.Text = "";
                en.mainEnq_Stu_Mobile = TextBox1.Text;

            }

        }

    }       
}

enter image description here 现在的问题是,我的页面上有三个面板,这些面板的可见性已被播放。在面板一上有两个单选按钮,它们决定两个面板第二和第三面板的对比度。第一个面板显示在第一页请求中。问题是我有下拉列表控件在第三个面板中打开自动回发。一旦由于ddl而返回帖子并且页面加载事件在那时触发

  

还检查AllOthers_Rdbtn.Checked,而不是显示第三个面板。 panel2再次显示。   我想要的是一种检查selectedindexchange事件是否与if语句中的Direct_Rdbtn.checked一起触发的方法。

1 个答案:

答案 0 :(得分:1)

您应该将代码移动到事件处理程序:

protected void Direct_Rdbtn_SelectedIndexChanged(object sender, EventArgs args)
{
    //If the enquiry is direct
    if (Direct_Rdbtn.Checked)
    {
        ...
    }
    else
    {
        ...
    }
}