Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:25:50+00:00 2026-05-28T08:25:50+00:00

I am trying to create an add to ‘favourites’button. When the user clicks this

  • 0

I am trying to create an add to ‘favourites’button. When the user clicks this button the image has to be changed ( in js). After that I would like to do a postback the asp.net page? how can I make this work? sofar i got:

aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            function ChangeFavStar() {
                if ($("#btnAddToFavs").attr('src') == 'starempty.jpg') {
                    $("#btnAddToFavs").attr('src') = 'staradded.jpg';
                }
                else {
                    $("#btnAddToFavs").attr('src') = 'starempty.jpg';
                }
                return true;
            }

        });

    </script>
    <style type="text/css">
        #btnAddToFavs {
            height: 79px;
            width: 121px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ImageButton ID=btnAddToFavs runat=server 
            OnClientClick="ChangeFavStar();" ImageUrl="~/starempty.jpg"
             Height="74px" Width="109px"  />

    </div>
    </form>
</body>
</html>

cs behindcode

 protected void btnAddToFavs_Click(object sender, ImageClickEventArgs e)
        {
            //do stuff
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:25:51+00:00Added an answer on May 28, 2026 at 8:25 am

    You may invoke JavaScript function but changes on button wont be persisted because of postback. You have to change ImageUrl property via C# code.

     <script type="text/javascript">
          function ChangeFavStar() {
             if ($("#btnAddToFavs").attr('src') == 'starempty.jpg') {
                  $("#btnAddToFavs").attr('src') = 'staradded.jpg';
              }
              else {
                  $("#btnAddToFavs").attr('src') = 'starempty.jpg';
              }
          }
        </script>
    

    Markup:

    <form id="form1" runat="server">
        <div>
        <asp:ImageButton ID="btnAddToFavs" runat=server 
                OnClientClick="ChangeFavStar();" ImageUrl="~/starempty.jpg"
                 Height="74px" Width="109px"  />
        </div>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an object called List. This object has a method add
I am trying to create a site that has option to add maps to
I am trying to create a simple ajax grid that allows me to add
I am trying to create an iPhone application where the user can add entries.
I'm am trying to create a jQuery plugin that will add new namespace functions
I am trying create a small web application that allows a user to login
Im trying to create a mp3 player that will add songs per day. So
Trying to create a page that allows users to add edit and view a
I'm trying to create a facility that will add some interceptor to the registered
I’m trying to create a COM User Defined Function automation add in for Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.