I have a div element:
<div class="tab-pane active" id="portlet_tab1">
I want to control this element from the code-behind page and remove the class "active"
NOTE:
Div doesn't contain the runat="server"
property.
This is not the master page file but this is another file named "AssignImages.aspx" and it contains ContentPlaceHolder.
The div is inside this ContentPlaceHolder:
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ID="Content1">
If you want to find the control from code behind you have to use runat="server"
attribute on control. And then you can use Control.FindControl
.
<div class="tab-pane active" id="portlet_tab1" runat="server">
Control myControl1 = FindControl("portlet_tab1");
if(myControl1!=null)
{
//do stuff
}
If you use runat server and your control is inside the ContentPlaceHolder
you have to know the ctrl name would not be portlet_tab1 anymore. It will render with the ctrl00 format.
Something like: #ctl00_ContentPlaceHolderMain_portlet_tab1. You will have to modify name if you use jquery.
You can also do it using jQuery on client side without using the runat-server attribute:
<script type='text/javascript'>
$("#portlet_tab1").removeClass("Active");
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With