Reputation: 2387
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.
Upvotes: 1
Views: 3143
Reputation: 2170
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.
}
}
Upvotes: 1