Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In master page I have a table id 'tgg' visible. In one of the content pages I want this table id 'tgg' to make invisible. I used the following code in content page which throws an error
like:Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlTable' to type
'System.Web.UI.WebControls.Table'.


C#
protected override void OnPreRender(EventArgs e)
    {
        ((Table)Master.FindControl("tgg")).Visible = false; //error on this line thrown
        base.OnPreRender(e);
    }
Posted

1 solution

Simply Try this:
HtmlTable dt = Master.FindControl("tgg");
dt.Visible = false;

Also add a runat="Server" to your table tag so that you can toggle its visibility / change its css.
if you want to expolore more about master pages.Here [^]is the basic tutorial
 
Share this answer
 
v2
Comments
S.Rajendran from Coimbatore 25-Apr-14 10:51am    
I tried:
protected override void OnPreRender(EventArgs e)
{
//((Table)Master.FindControl("tgg")).Visible = false;
//base.OnPreRender(e);
HtmlTable dt = Master.FindControl("tgg");
dt.Visible = false;
}
error; ARe you missing a cast? is appearing!
Schatak 26-Apr-14 2:10am    
try this<br>
Table tbl = (Table)this.Master.FindControl("ContentPlaceHolder1").FindControl("table");
ContentPlaceHolder1: your ContentPlaceHolder ID on Master page
table: table id in Master page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900