Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
this is my first project in asp.net. I have done numeric paging using repeater
ASP
<asp:Repeater ID="Repeater1" runat="server">
                    <itemtemplate>
                        <asp:LinkButton ID="lnkPageno" OnClick="lnkPageno_Click" Text="<%#Container.DataItem %>"
                            runat="server">
                    </itemtemplate>


I tried to change the color of the clicked number (eg., 2 out of 1 to 10) dynamically. i applied CSS, still color of the current page not changed. Can anyone help me?
Posted
Updated 9-Feb-13 23:00pm
v2
Comments
Dee_Bee 11-Feb-13 23:43pm    
<asp:Repeater ID="Repeater1" runat="server">
<itemtemplate>
<asp:LinkButton ID="lnkPageno" ForeColor="Red" OnClick="lnkPageno_Click" Text="<%#Container.DataItem %>"
runat="server">


Check the Forecolor property, as I gave Red, u can give any color as u wish

Check following link.
They have used javaScript to change linkbutton color on click.
Check answer no2.

Refer - ASP.NET Change link button color when clicked without post-back or update panel[^]
 
Share this answer
 
v2
ASP.NET
<asp:linkbutton id="lnkPageno" 
                onclientclick="return Color(this);" 
                text="<%#Container.DataItem %>">
</asp:linkbutton>


The javaScript now:
JavaScript
function Color(evt){
     evt.style.Color = "your_Color";
}
 
Share this answer
 
v2
Assuming this is the HTML and the link current goes nowhere, you have to change the href value to a valid URL:

HTML
<a href="#" id="mylink" style="color:blue;">My blue link</a>


Notice that I gave it an id, that's for the javascript to turn it to different color and identify this tag.

JavaScript
window.onload = function() {
  document.getElementById('mylink').onclick = function() {
    this.style.color = 'green';
  }
}
 
Share this answer
 
v2
Since you are firing a server side event lnkPageno_Click, you can change the color of clicked button. Write the code snippet in lnkPageno_Click event.
C#
LinkButton lnk = (LinkButton)sender;
lnk.ForeColor = System.Drawing.Color.Red;



--Amit
 
Share this answer
 
Comments
sukumari1 11-Feb-13 9:47am    
Yes, it works. But when i click the other link button(3) the old one (2) also retain the same color. i want only one link button color to be changed at a time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900