asp:ImageButton 与 PostBackUrl 在第二次单击后响应
我有一个带有 PostBackUrl 的 asp:ImageButton 到同一个按钮(代码后面),我必须单击两次才能触发内部代码。我需要知道如何一键解决这个问题。请参阅下面的代码。
<asp:ImageButton ID="imgButton" runat="server" ImageUrl="~/images/compose.gif" OnClick="imgButton_Click"/>
背后代码:
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).
}
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).
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仅在第一次点击时设置 postbackurl 属性,而不是回发给它。然后,在第二次单击时,它会发回 url,因为该属性已在第一次单击时设置。在标记中设置 postbackurl 属性或在按钮单击事件中执行 Response.Redirect。
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.