0

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......

Edited by mani508

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by mani508
1

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.

Votes + Comments
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...??

0

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.

0

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

0

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.

This question has already been answered. 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.