[RESOLVED]Need to access content page panel from master page

Hi,
I have a dropdownlist in my master page and upon select certain items, I want the panel to appear and disappear, which is on the content page. What would be the best way to accomplish this. Can I call JS of content from master? 

We can use FindControl method to do this.

Refer this article

http://www.aspdotnet-suresh.com/2012/06/aspnet-how-to-access-content-page.html

Example snippet:

Panel panelContent = ContentPlaceHolder1.FindControl("pnlContent") as Panel;
panelContent.Visible = false; // or true based on your requirement.

Thank you for your response.
Sorry  I should have mentioned, I have been asked not to use any codebehind if possible and do it through JS.

Sure, you can take out the Control Id generated (if you would like to use pure html and js) and write the javascript to hide/show.

If you are using jQuery:

For hiding:
$('#generatedPanelID').hide();

For Showing:
$('#generatedPanelID').show();

For plain javascript:

document.getElementById('generatedPanelID').style.display = 'none'; 
// none for hide, inline or block for show.

Note: The panel ID will not be the one which you see in design page, but it will be auto generated when rendered to the client. So, just do a view source to get the exact id.

Or, you can also try use inline scripts something like this, note: I’ve just handcrafted the code, not tested so you may need to cast it to Panel first before accessing ClientID if it doesn’t work directly:

var ctrlId = '<%= ContentPlaceHolder1.FindControl("pnlContent").ClientID %>';
document.getElementById(ctrlId).style.display = 'none';

Thank you very much! That worked like a charm.

You’re welcome, have a nice day!

Hi,

Panel pnl = (Panel)Master.FindControl("pnl_heading");
pnl.Visible=true;
pnl.BackColor = Color.FromName("blue");

Check this out……

U can have more like this from 

n4narendran.blogspot.in

Leave a Reply