开发者

asp:ImageButton with PostBackUrl responds after the second click

开发者 https://www.devze.com 2023-03-04 23:41 出处:网络
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 cl

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号