Question

Error Message displayed as "AddFavoriteRadWindow not found"

My code:

protected void btnAddReport_Click(object sender, ImageClickEventArgs e)
    {
         this.form1.Controls.Add(AddFavoriteRadWindow); // working fine
    }

protected void btnOk_Click(object sender, EventArgs e)
{
    if (txtReportFavorite.Text != string.Empty)
    {
        // code for inserting into db..
        AddFavoriteRadWindow.Visible = false; // not working 
    }
}

"AddFavoriteRadWindow not found" message is displayed when I want to hide the rad window

Was it helpful?

Solution

You need to get the instance of your added controls from your Control Collection. Try

(this.form1.FindControl(AddFavoriteRadWindow.ID) as RadWindow).Visible = false;

You may put a check in place against null. Something like.

if((this.form1.FindControl(AddFavoriteRadWindow.ID) as RadWindow) != null)

(I am not sure about your class name, I have used RadWindow but you can replace that with your class name)

EDIT: You should pass the string id of the control in your FindControl method to get that specific control back

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top