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 b开发者_开发问答ellow.
<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).
}
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.
精彩评论