Create an ImageButton that toggles imageurl on click dynamically in ASP.NET
<p>I wanted to created an imagebutton in asp.net which changes its imageurl on click, i use it for selecting seats in reservation system when we click it must change to selected imageurl and if we click on selected image it must change to avaialble image url, actually i am new to asp.net and i had tried it using simple if loop, it works for selection but the selection doesnot change to unselect. Could any one help me witht that even using javascript, i had seen on some sites using javascript but i don't know javascript. Here is the code i had written the else loop is not working always goes to 1st condition.</p>

<pre><code>protected void ib_s1_Click(object sender, ImageClickEventArgs e)
    {
        onclick(ib_s1);//Call fun on click
    }

public void onclick(ImageButton tib)
    {
        String selseats, temp; //store temp data
        int n=0; //use to count
        ImageButton tempib = tib;
        if (tempib.ImageUrl == "~/graphics/Available.jpg")
        {
            tempib.ImageUrl = "~/graphics/Selected.jpg"; //change image url
            selseats = tempib.ID.ToString();
            temp = selsea.Text.Trim().ToString();
            temp = temp + selseats + ",";
            selsea.Text = temp; //store the selected seats to text box
            n++; //count
        }
        else if (tempib.ImageUrl == "~/graphics/Selected.jpg")
        {
            tempib.ImageUrl = "~/graphics/Available.jpg"; //if else or click again
        }

    }
</code></pre>
