图像按钮点击在更新面板中不起作用,我怎样才能让它工作
本文关键字:工作 不起作用 按钮 更新 图像 | 更新日期: 2023-09-27 18:24:09
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="true"
runat="server">
<ContentTemplate>
<asp:ImageButton ID="imagebutton1" runat="server" ImageUrl="~/image.jpg" Width="125"
Height="125" onclick="imagebutton1_Click" />
<asp:Timer ID="timer1" runat="server" Interval="10000" ontick="timer1_Tick" />
<asp:Label ID="label1" Visible="false" runat="server" Text="" />
</ContentTemplate>
</asp:UpdatePanel>
如果我不使用更新面板,整个页面都会刷新。
protected void imagebutton1_Click(object sender, ImageClickEventArgs e){
string link = label1.Text;
Page.ClientScript.RegisterStartupScript(this.GetType(), "OPEN", "window.open(" + link +
",'mywindow','width=200,height=200,');", true);
}
这是计时器处理程序中的变量"链接">
Random r = new Random();
if (datatable1.Rows.Count > 0)
{
int randomnumber = r.Next(0, i);
DataRow datarow1= datatable1.Rows[randomnumber ];
imagebutton1.ImageUrl = (String)datarow1["image"];
imagebutton1.DataBind();
label1.Text = (String)datarow1["Link"];
}
我只需要添加回发触发器,如下所示的更新面板才能使其工作。
<Triggers>
<asp:PostBackTrigger ControlID="ImageButton"/>
</Triggers>
很难说,因为您并没有真正包含问题,但是如果您希望在 UpdatePanel 刷新时运行一段客户端代码,请使用客户端pageLoad()
方法。
此外,您正在使用服务器端事件来执行客户端操作。请改用OnClientClick
处理程序:
<asp:ImageButton ID="imagebutton1" runat="server" ImageUrl="~/image.jpg" Width="125"
Height="125" OnClienClick="return openPopUp(this.href);" />
function openPopUp(link)
{
window.open(this.href,'mywindow','width=200,height=200,');
return false;
}
尝试更改为UpdateMode="Always"