Carlos
Carlos

Reputation: 1003

asp:ImageButton with PostBackUrl responds after the second click

I have an asp:ImageButton with a PostBackUrl into the same button (code behind) and I have to click twice in order to fire the internal code. I need to know how can I solve this issue just with one click. Please see code bellow.

<asp:ImageButton ID="imgButton"  runat="server"  ImageUrl="~/images/compose.gif" OnClick="imgButton_Click"/>

Code Behind:

protected void imgButton_Click(object sender, ImageClickEventArgs e)
{


        this.imgButton.PostBackUrl = "http://www.externalSite.com/Entry.aspx";
        //The internal code goes here... (this responds after second click).

}

Upvotes: 0

Views: 1876

Answers (1)

Coding Flow
Coding Flow

Reputation: 21881

You are only setting the postbackurl property on the first click, not posting back to it. Then on the second click it posts back to the url because the property has been set on the first click. Either set the postbackurl property in the markup or do a Response.Redirect in the button click event.

Upvotes: 2

Related Questions