1
votes

I am working in C#.Net. I am having ASPX Page and ASCX Page. In my ASCX page, there is a textbox and HTML Image button. I want to do the enable true and false process based on the dropdown selected index changed event. By default, the textbox should be disabled and Image should be visibled false.

Here is my ASPX Page Load..

 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;
       }

and my ASCX Code..

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

The value are passing correctly to the property. But the textbox control is in disabled mode only and image is in visible false. How to enable and visible the controls.

1
You use both Enabled and Visible, is that a typo in the post? - Hans Kesting
yes...i am using enable for textbox and visible for html image... - RobinHood
I'm curious about the scope of PI_CompLocationTree1? Is it defined within the aspx page, or are you using nested master pages? Are you able to access PI_CompLocationTree1 directly from the page without using FindControl? The best answer may differ depending on these conditions. - Glen Hughes

1 Answers

1
votes

Instead of doing it in Page_Load event, do it in Page_Init event.

To get the selected value of dropdown list in Page_Init event you can use this approach:

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.
            }
        }