【问题标题】:how to check if the ddl.selectedindexchange event has been fired on the page load如何检查页面加载时是否触发了 ddl.selectedindexchange 事件
【发布时间】:2014-03-27 18:42:53
【问题描述】:

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

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;

            }

        }

    }       
}

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!!它完美无缺。我多么愚蠢,没想到这个大声笑:D
    猜你喜欢
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多