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.
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.
If you are using jQuery:
For hiding: $('#generatedPanelID').hide(); For Showing: $('#generatedPanelID').show();
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!
Panel pnl = (Panel)Master.FindControl("pnl_heading");
pnl.BackColor = Color.FromName("blue");
Check this out……
U can have more like this from