0

Hi, how can I change the HTML code via VB .Net code?

For example,

on .aspx file I have:

<div class="Menu_On"><asp:LinkButton ID="Link_Menu1" runat="server">Menu 1</asp:LinkButton></div>
<div class="Menu_Off"><asp:LinkButton ID="Link_Menu2" runat="server">Menu 2</asp:LinkButton></div>
<div class="Menu_Off"><asp:LinkButton ID="Link_Menu3" runat="server">Menu 3</asp:LinkButton></div>

Then, when I click the "Menu 2" link, the class which coping the link should change become "Menu_On", and the other class become "Menu_Off".

How can I do that?

Thank you so much.

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by hericles
0

Do it client side with javascript. Add an onclientclick event and then alter the css class the element is pointing to.
Your HTML:
div id="menu1' class="Menu_On"><asp:LinkButton ID="Link_Menu1" runat="server" onclientclick='changeCSS(1);'>Menu 1</asp:LinkButton></div>
div id='menu2' class="Menu_Off"><asp:LinkButton ID="Link_Menu2" runat="server" onclientclick='changeCSS(2);'>Menu 2</asp:LinkButton></div>
div id='menu3' class="Menu_Off"><asp:LinkButton ID="Link_Menu3" runat="server" onclientclick='changeCSS(3);'>Menu 3</asp:LinkButton></div>

Your javascript:
function changeCSS(number) {
document.getElementById('menu1').className += "Menu_Off"; // set them all to off
document.getElementById('menu2').className += "Menu_Off";
document.getElementById('menu3').className += "Menu_Off";
var menu = 'menu' + number;
document.getElementById(menu).className += "Menu_On"; // reset correct menu to on - yes, its a lazy way to do :)
}

You only mention 3 menus but if you have more the javascript function can be made more dynamic. You should be able to get the idea anyway. A loop could be used to run through them all to set them to false.

OK, I don't see how to indent code lines any more...

Edited by hericles: trying to make code lines display

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.