hello i want to change text while pressing the linkbutton. i want to add feature like and dislike on website.. that's why i add two link button one is Like and other is Dislike...
i am so confused about it when user press the like button then change the text of like into unlike. then if user press the unlike then show the like text... how its possible kindly tell me as soon as possible thanks in advance......

LinkButton.Text = "Like";

You will want the code to check the current text of the button so it knows what to change to I guess. An if statement will do that easily enough:

if(LinkButton1.Text == "Like") {
    LinkButton1.Text = "Unlike";
    // plus whatever other codes runs when something is liked
} else {
    LinkButton1.Text = "Like";
}

Initially you will want to show two buttons (like and dislike) but once a selection is made you would be better to hide one of the buttons as only one is needed now - to reverse the decision. For example, if I like the page there is no point changing the like button to unlike because there will now be unlike and dislike which is pretty confusing to the user. Better to change its visibility instead and leave the dislike button unchanged.

commented: n!ce help +0

ok thanks alot i got it....
i want to user hit the like button then 1 increment of like count and also that user see liked or unlike text and if user next time login or refresh the page then like text not show if that user like already . show liked or unlike on page load how can i do that...??

In the page load method add your code that calculates the number of likes (from a database most likely) and figure out what text is displayed on the buttons.

ok but if user already like then how disable like button on page load method??

You would need some way of knowing when a user has liked a page, so the like button doesn't show again and the unlike option is there. I'm assuming you will be saving this in a database so when the page loads the code checks if this user has liked or disliked this page and, knowing that, can figure out what button to show and what text to display.

ok thanx...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.