How to show and hide controls in content page using javascript?http://forums.asp.net/t/1757769.aspx/1?How+to+show+and+hide+controls+in+content+page+using+javascript+Sat, 14 Jan 2012 07:10:03 -050017577694775012http://forums.asp.net/p/1757769/4775012.aspx/1?How+to+show+and+hide+controls+in+content+page+using+javascript+How to show and hide controls in content page using javascript? <p>HI</p> <p>I have a code mention below. My task is to hide <strong>ddlstSchemaNames and lblSchema on page load and </strong>when i&nbsp;select value from <strong>ddlstAllCISTables&nbsp;&nbsp;</strong>i have to show <strong>ddlstSchemaNames and lblSchema&nbsp; using javascript? how to do this?</strong></p> <pre class="prettyprint">&lt;asp:Content ID=&quot;Content2&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt; &lt;table cellpadding=&quot;3&quot; width=&quot;100%&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style1&quot; align=&quot;center&quot;&gt; &lt;asp:Label ID=&quot;lblTableNames&quot; runat=&quot;server&quot; Text=&quot;Select Source Table&quot;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align=&quot;left&quot;&gt; &lt;asp:DropDownList name=&quot;<strong>ddlstAllCISTables</strong>&quot; ID=&quot;<strong>ddlstAllCISTables</strong>&quot; runat=&quot;server&quot; Height=&quot;25px&quot; Width=&quot;220px&quot; OnSelectedIndexChanged=&quot;ddlstAllCISTablesChanged&quot;&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style1&quot; align=&quot;center&quot;&gt; &lt;asp:Label ID=&quot;lblSchema&quot; runat=&quot;server&quot; Text=&quot;Select Target Schema&quot;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align=&quot;left&quot;&gt; &lt;asp:DropDownList ID=&quot;<strong>ddlstSchemaNames</strong>&quot; runat=&quot;server&quot; Height=&quot;25px&quot; Width=&quot;200px&quot; OnSelectedIndexChanged=&quot;ddlstSchemaNamesChanged&quot; onchange=&quot;ShowButton();&quot;&gt; &lt;asp:ListItem Text=&quot;-- Select Schema --&quot; Value=&quot;-- Select Target Schema --&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;bdsp&quot; Value=&quot;bdsp&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;oltpdev&quot; Value=&quot;oltpdev&quot;&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&quot;2&quot; align=&quot;center&quot;&gt; &lt;asp:Button ID=&quot;btnCompare&quot; runat=&quot;server&quot; Text=&quot;Compare&quot; Visible=&quot;false&quot; ToolTip=&quot;Click to compare two tables&quot; OnClick=&quot;btnCompare_Click&quot; /&gt; &lt;/td&gt; &lt;/tr&gt;</pre> 2012-01-10T11:13:47-05:004775032http://forums.asp.net/p/1757769/4775032.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Are you using jQuery in your application??&nbsp;</p> <p>If so, I can provide you with jQuery code.</p> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T11:25:08-05:004775034http://forums.asp.net/p/1757769/4775034.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Thanks</p> <p>please provide in jQuery</p> 2012-01-10T11:27:13-05:004775067http://forums.asp.net/p/1757769/4775067.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>&lt;script type=&quot;text/javascript&quot;&gt;</p> <p>var ddlId= '&lt;%=ddlstAllCISTables.ClientID%&gt;';</p> <p>&#36;('#' &#43; ddlId).change(function(){</p> <p>&#36;('#trddls').show('slow');</p> <p>});</p> <p>&lt;/script&gt;</p> <p></p> <p>you have to assign ID to &lt;tr&gt; containing dropdownlists.. like</p> <pre class="prettyprint">&lt;tr id=&quot;trddls&quot; style=&quot;display:none;&quot;&gt; &lt;td class=&quot;style1&quot; align=&quot;center&quot;&gt; &lt;asp:Label ID=&quot;lblSchema&quot; runat=&quot;server&quot; Text=&quot;Select Target Schema&quot;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align=&quot;left&quot;&gt; &lt;asp:DropDownList ID=&quot;<strong>ddlstSchemaNames</strong>&quot; runat=&quot;server&quot; Height=&quot;25px&quot; Width=&quot;200px&quot; OnSelectedIndexChanged=&quot;ddlstSchemaNamesChanged&quot; onchange=&quot;ShowButton();&quot;&gt; &lt;asp:ListItem Text=&quot;-- Select Schema --&quot; Value=&quot;-- Select Target Schema --&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;bdsp&quot; Value=&quot;bdsp&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;oltpdev&quot; Value=&quot;oltpdev&quot;&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt;</pre> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T11:41:50-05:004775085http://forums.asp.net/p/1757769/4775085.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>hi</p> <p>Now i want to show <span class="tag">&lt;tr id=&quot;trddls&quot; style=&quot;display:none;&quot;&gt; </span> when user select an item from the first dropdownlist. How?</p> <p>Thanks</p> 2012-01-10T11:50:14-05:004775087http://forums.asp.net/p/1757769/4775087.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>I gave you jQuery code</p> <p>&lt;script type=&quot;text/javascript&quot;&gt;</p> <p>var ddlId= '&lt;%=ddlstAllCISTables.ClientID%&gt;';</p> <p>&#36;('#' &#43; ddlId).change(function(){</p> <p>&#36;('#trddls').show('slow');</p> <p>});</p> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T11:51:37-05:004775108http://forums.asp.net/p/1757769/4775108.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>hi</p> <p>when i select value from ddlstAllCISTables it is now showing dropdownlist i.e ddlstSchemaNames. When i select value from ddlstAllCISTables it should show the other controls. how?</p> <p><span color="#0000ff" size="2" face="Consolas" style="font-family:Consolas; color:#0000ff; font-size:x-small"><span color="#0000ff" size="2" face="Consolas" style="font-family:Consolas; color:#0000ff; font-size:x-small"><span color="#0000ff" size="2" face="Consolas" style="font-family:Consolas; color:#0000ff; font-size:x-small"></span></span></span></p> 2012-01-10T12:01:07-05:004775121http://forums.asp.net/p/1757769/4775121.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Which Other Controls??</p> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T12:06:33-05:004775130http://forums.asp.net/p/1757769/4775130.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>sorry</p> <p>read this reply</p> <p>when i select value from ddlstAllCISTables it is not showing dropdownlist i.e ddlstSchemaNames. When i select value from ddlstAllCISTables it should show the other controls i.e ddlstSchemaNames and label ( <strong>i.e tr) </strong>. how?</p> 2012-01-10T12:12:13-05:004775140http://forums.asp.net/p/1757769/4775140.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Did you use jQuery code??</p> <p>it should work as expected.</p> <p>can you post full .aspx Code?</p> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T12:14:44-05:004775228http://forums.asp.net/p/1757769/4775228.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>hi</p> <p>here is my full code</p> <pre class="prettyprint">&lt;script src='&lt;%=ResolveClientUrl(&quot;~/Scripts/jquery-1.4.1.min.js&quot;)%&gt;' type=&quot;text/javascript&quot;&gt;&lt;/script&gt; // In master page &lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;HeadContent&quot; runat=&quot;server&quot;&gt; &lt;script type=&quot;text/javascript&quot;&gt; var ddlId = '&lt;%=ddlstAllCISTables.ClientID%&gt;'; $('#' &#43; ddlId).change(function () { $('#trddls').show('slow'); }); &lt;/script&gt; &lt;asp:Content ID=&quot;Content2&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt; &lt;table cellpadding=&quot;3&quot; width=&quot;100%&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style1&quot; align=&quot;center&quot;&gt; &lt;asp:Label ID=&quot;lblTableNames&quot; runat=&quot;server&quot; Text=&quot;Select Source Table&quot;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align=&quot;left&quot;&gt; &lt;asp:DropDownList name=&quot;ddlstAllCISTables&quot; ID=&quot;ddlstAllCISTables&quot; runat=&quot;server&quot; Height=&quot;25px&quot; Width=&quot;220px&quot;&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr id=&quot;trddls&quot; style=&quot;display:none;&quot;&gt; &lt;td class=&quot;style1&quot; align=&quot;center&quot;&gt; &lt;asp:Label ID=&quot;lblSchema&quot; runat=&quot;server&quot; Text=&quot;Select Target Schema&quot;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align=&quot;left&quot;&gt; &lt;asp:DropDownList ID=&quot;ddlstSchemaNames&quot; runat=&quot;server&quot; Height=&quot;25px&quot; Width=&quot;200px&quot; OnSelectedIndexChanged=&quot;ddlstSchemaNamesChanged&quot;&gt; &lt;asp:ListItem Text=&quot;-- Select Schema --&quot; Value=&quot;-- Select Target Schema --&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;bdsp&quot; Value=&quot;bdsp&quot;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&quot;oltpdev&quot; Value=&quot;oltpdev&quot;&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt;</pre> 2012-01-10T12:58:11-05:004775631http://forums.asp.net/p/1757769/4775631.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>try this</p> <pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function(){ var ddlId = '&lt;%=ddlstAllCISTables.ClientID%&gt;'; $('#' &#43; ddlId).change(function () { $('#trddls').show('slow'); }); }); &lt;/script&gt;</pre> &lt;div id=&quot;-chrome-auto-translate-plugin-dialog&quot; style=&quot;opacity: 1 !important; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: transparent !important; position: absolute !important; top: 0px; left: 0px; overflow-x: visible !important; overflow-y: visible !important; z-index: 999999 !important; text-align: left !important; display: none; background-position: initial initial !important; background-repeat: initial initial !important; padding: 0px !important; margin: 0px !important;&quot;&gt; &lt;div style=&quot;max-width: 300px !important; color: #fafafa !important; opacity: 0.8 !important; border-color: #000000 !important; border-width: 0px !important; -webkit-border-radius: 10px !important; background-color: #363636 !important; font-size: 16px !important; padding: 8px !important; overflow: visible !important; background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #000), color-stop(50%, #363636), color-stop(100%, #000)); z-index: 999999 !important; text-align: left !important;&quot;&gt; &lt;div class=&quot;translate&quot;&gt;&lt;/div&gt; &lt;div class=&quot;additional&quot;&gt;&lt;/div&gt; &lt;/div&gt; <img src="http://www.google.com/uds/css/small-logo.png" style="">&lt;/div&gt; 2012-01-10T16:28:53-05:004776317http://forums.asp.net/p/1757769/4776317.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>hi</p> <p>Still not working. please any other way,</p> <p>Thanks</p> 2012-01-11T05:03:21-05:004778398http://forums.asp.net/p/1757769/4778398.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Hi,</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>athar_techsavvy</h4> <p></p> <p>please any other way,</p> <p></p> </blockquote> <p></p> <p>You can add a onchange event using javascript in codebehind.</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { ddlstAllCISTables.Attributes.Add(&quot;onchange&quot;, &quot;javascript:document.getElementById('trddls').style.display = 'inline';&quot;); }</pre> 2012-01-12T04:55:48-05:004782184http://forums.asp.net/p/1757769/4782184.aspx/1?Re+How+to+show+and+hide+controls+in+content+page+using+javascript+Re: How to show and hide controls in content page using javascript? <p>Hi</p> <p>i tried your code</p> <pre class="prettyprint">ddlstAllCISTables.Attributes.Add(&quot;onchange&quot;, &quot;javascript:document.getElementById('trddls').style.display = 'inline';&quot;); }</pre> <pre class="prettyprint">still not working. Anyhow i got the working code like this.</pre> <pre class="prettyprint">&lt;script type="text/javascript" src="&lt;%=ResolveClientUrl("~/js/jquery-1.6.1.js")%&gt;"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; &#36;(document).ready(function() { var ddlId = '&lt;%=ddList.ClientID%&gt;'; &#36;('#' + ddlId).change(function() { if (&#36;('#&lt;%=ddList.ClientID%&gt;').val() == "2") { //&#36;('#&lt;%=dd2.ClientID %&gt;').empty().append('&lt;option selected="selected" value="0"&gt;Please select&lt;/option&gt;'); &#36;('#&lt;%=dd2.ClientID %&gt;').hide(); } else { &#36;('#&lt;%=dd2.ClientID %&gt;').show(); } }); }); &lt;/script&gt; &lt;div id="trddls"&gt; &lt;asp:DropDownList ID="ddList" runat="server"&gt; &lt;asp:ListItem Value="1" Text="Show"&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="2" Text="Hide"&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:DropDownList ID="dd2" runat="server"&gt; &lt;/asp:DropDownList&gt; &lt;/div&gt;</pre> 2012-01-14T07:10:03-05:00