1

我在 C#.Net 中工作。我有 ASPX 页面和 ASCX 页面。在我的 ASCX 页面中,有一个文本框和 HTML 图像按钮。我想根据下拉选择的索引更改事件来启用真假过程。默认情况下,文本框应该被禁用并且图像应该是可见的。

这是我的 ASPX 页面加载..

 ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("ContentPlaceHolder1");
 PI_CompLocationTree userCntrl = (PI_CompLocationTree)cph.FindControl("PI_CompLocationTree1");
      userCntrl.TextBoxUSC = false;
      userCntrl.ImgUSC = false;

      if (analysisGroup.SelectedValue == "0")
       {
            userCntrl.TextBoxUSC = true;
            userCntrl.ImgUSC = true;
       }
      else if (analysisGroup.SelectedValue == "1")
       {
            userCntrl.TextBoxUSC = true;
            userCntrl.ImgUSC = true;
       }
      else
       {
            userCntrl.TextBoxUSC = false;
            userCntrl.ImgUSC = false;
       }

和我的 ASCX 代码..

public bool TextBoxUSC
    {
        set { txtLoc.Enabled = value; }
    }
    public bool ImgUSC
    {
        set { imgEdit.Visible = value; }
    }

该值正确传递给属性。但是文本框控件仅处于禁用模式,并且图像处于可见状态。如何启用和显示控件。

4

1 回答 1

1

与其在事件中做,不如在Page_Load事件中做Page_Init

要在 Page_Init 事件中获取下拉列表的选定值,您可以使用以下方法:

if (Request["__EVENTTARGET"] != null)
        {
            string controlID = Request["__EVENTTARGET"];
            if (controlID.Equals(analysisGroup.ID))
            {
                string selectedValue =  Request.Form[Request["__EVENTTARGET"]].ToString();
                Session["SelectedValue"] = selectedValue; //Keep it in session if other controls are also doing post backs.
            }
        }
于 2012-08-30T06:52:18.193 回答