i am trying to hide a div which written in a ascx , i am hiding it from code behind of aspx page where this ascx is registerd.
here is my hidng code
My div code is here :
<div class="form-group col" runat="server" id="CorpCol" visible="false">
Here is my code behind
System.Web.UI.Control CorpCol = FindControlRecursive(this.Master, "CorpCol");
CorpCol.Visible = false;
2
Answers
you must chaning style in code behind:
But the easiest way is to use JavaScript.
You can add jQuery to project and put the following code at the bottom of your page:
I suggest you modify the user control, and expose that "div" as a public property of the user control.
Not only then does your code become rather simple, but you also find when you drop multiple instances of that user control on a page, then the hide/show of each "instance" of that div becomes nice clean and easy code.
So, say a user control to select a hotel, then a start, and end date.
And let’s have "div" in that user control that we want to hide (or show).
So, our simple user control markup is this:
And the code for the user control:
Note how we just expose the "div" as a public property. And since it is an object, then no "setter" is required, only the above "get". And note the “id" and runat="server" tag for that div.
Ok, now our web page. Let’s drop in the user control 2 times, and then have 2 buttons. One to hide (or show) the first user control div. The 2nd button will hide/show the 2nd user control div.
So, this markup:
And the code behind for the 2 buttons:
So note how we can in code behind set USelecthotel1.MyDiv.Visible = false in code.
The result of above looks like this: