Reputation: 12533
this question might sound silly to some but i just had to make sure.
iv'e got a control which is not visible (visible = false) i want it to become visible under certain conditions for instance onmoueover of a certain textbox ,
can i perform client side events such as this on server controls ?
iv'e noticed that i can't even give the onmouseover event if the control is set to run at server.
to summarize , is there a way the make a server control visible from the client side with out having to post back to the server .
thanks for the answer from before but i came across a new problem :
my control is a calendar which is placed inside a content page ,
when i click on a textbox i want it to appear but when it is set to Visible=false the client side script isn't able to locate it :
function Show_Calander() {
debugger;
var c = document.getElementById('<%= calander1.ClientID %>');
c.visible = true;
}
<input type="text" id="txt_date" runat="server" onclick="Show_Calander();"/>
<asp:Calendar ID="calander1" runat="server" Visible="False"></asp:Calendar>
i can do this form the server side but i just want to increase performance by not going to the server for every little thing.
any ideas how i could make this happen ?
Upvotes: 0
Views: 1620
Reputation: 755557
Yes this is certainly possible with javascript. Each control has a ClientID
property which can be used to reference it from javascript. Here's a quick example with jQuery on how to make a particular Asp.Net control visible on a click event
<asp:TextBox ID="txtUsername" Runat="server" />
<button id='theButton'>Make it Visible</button>
JQuery Code
$(document).ready(function() {
$('#theButton').click(function() {
var id = '#' + '<%= txtUsername.ClientID %>';
$(id).show();
});
});
Upvotes: 2