Reputation: 6090
Wondering if there is a way upon clicking on a hyper link to set drop downlist to visible in code behind or asp?
<asp:HyperLink ID="HyperLink2" runat="server">View More Workout Programs »</asp:HyperLink>
Upvotes: 0
Views: 307
Reputation: 905
If you need to send form back to the server, use asp:LinkButton instead and handle OnClick event on the server side. If you need to show drop down list on the client side, use javascript function with onclick client event to show or hide any section you want.
Upvotes: 0
Reputation: 219016
If you have to do it in code-behind, then use a LinkButton
instead of a HyperLink
. Then it will have a click event just like any button and in that click event you can set the other element to .Visible=true
.
However, does this need to be done in code-behind? Keep in mind the difference in "visibility" between server-side and client-side code:
.Visible=false
on the server-side, the content is not delivered to the client at all.display:none
on the client-side, the content is present and can be viewed in the page source, it's just not displayed by the browser.In some cases, the former is needed for security purposes. But if it's just a matter of user experience then I would recommend showing/hiding the content entirely on the client-side so as to avoid post-backs that do nothing more than change element display properties.
For example (assuming jQuery):
<a id="toggler" href="#">Show the content</a>
<div id="hidden" style="display:none;">Content</div>
<script>
$(document).ready(function(){
$("#toggler").click(function(){
$("#hidden").show();
});
});
</script>
Upvotes: 2
Reputation: 31202
You can try with JQuery : http://www.jquery.com
It will be something like
<script type="text/javascript">
$(document).ready(function(){
$("#<% =HyperLink2.ClientID %>").click(function() {
$("#<% =DropDownList1.ClientID %>").toggle();
});
});
</script>
Upvotes: 0
Reputation: 8360
You should implement that kind of feature in the client (javascript code) to improve user experience.
Anyway, you can use a Panel with Visibility=false and put Visibility=true in code behind when link is clicked. You would need to adjust the position of that panel with css to look like a dropdown.
Upvotes: 0
Reputation: 7119
Use an asp:LinkButton
instead of a hyperlink and handle the OnClick
event. In the OnClick
event, toggle myDropDownList.Visible
depending on whether you want to show it or not.
Upvotes: 1