admin管理员组文章数量:1394991
in an asp page I have a list of Link buttons:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Link_Click">Link 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="Link_Click">Link 2</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" OnClick="Link_Click">Link 3</asp:LinkButton>
I am using them as triggers for an update panel on the site. When a user clicks on a link a control gets loaded on the page.
What I want is this:
Whne the user clicks on a link the color of that link change so we can know which link was pressed last.
I would like to do this without post-back or update panels. So is there a way to do this via javascript? or other solutions?
Thank you for any help
in an asp page I have a list of Link buttons:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Link_Click">Link 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="Link_Click">Link 2</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" OnClick="Link_Click">Link 3</asp:LinkButton>
I am using them as triggers for an update panel on the site. When a user clicks on a link a control gets loaded on the page.
What I want is this:
Whne the user clicks on a link the color of that link change so we can know which link was pressed last.
I would like to do this without post-back or update panels. So is there a way to do this via javascript? or other solutions?
Thank you for any help
Share Improve this question asked Nov 25, 2011 at 17:56 Y2theZY2theZ 10.4k39 gold badges134 silver badges204 bronze badges2 Answers
Reset to default 4JAVASCRIPT:
<script>
function changeColor(e) {
e.style.color = "red";
return false;
}
</script>
HTML:
<asp:LinkButton ID="LinkButton1" OnClientClick="return changeColor(this);" runat="server">LinkButton</asp:LinkButton>
Good luck!
Sure, there's a way with JavaScript. You could hook up an event to the OnClientClick
attribute of your LinkButton
s and run some client-side code.
You might want to create some CSS for the two states of that button. It would be easier to assign new classes to the buttons than to change all of their styling with JavaScript.
If you were willing to use a library like jQuery, it would be really easy:
Assign a matching CSS class "A" to each button.
<asp:LinkButton ID="Button1" CssClass="button button-off" runat="server" /> <asp:LinkButton ID="Button2" CssClass="button button-off" runat="server" />
Create a "B" CSS class that is the "off" state and "C" class that is the "On" state.
Assign a click handler to each button that has the "A" class. Something like this (untested):
$('.button').click(function() { $('.button').removeClass('button-on'); $(this).addClass('button-on'); });
The click handler above should behave so that it clears the "B" class from all of the buttons with class "A" and assigns the "C" class to the button that was clicked.
版权声明:本文标题:javascript - ASP.NET Change link button color when clicked without post-back or update panel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744110632a2591276.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论