Imagebutton onclick 在 updatepanel 中不起作用,我怎样才能使它工作?
<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);
}
这是计时器处理程序中的变量“link”
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"];
}
<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>
If I don't use an update panel the whole page refreshes.
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);
}
This is the variable "link" here in the timer handler
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"];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我必须在更新面板中添加回发触发器,如下所示才能使其工作。
I had to just add postback triggers as shown below in the updatepanel to make it work.
很难说,因为您并没有真正包含问题,但如果您希望在 UpdatePanel 刷新时运行一段客户端代码,请使用客户端
pageLoad()
方法。此外,您正在使用服务器端事件来执行客户端操作。请改用
OnClientClick
处理程序:It's hard to say since you didn't really include a question, but if you want a piece of client side code to run when an UpdatePanel refreshes, use the client side
pageLoad()
method.Also, you are using a server side event to do a client side operation. Use the
OnClientClick
handler instead:尝试更改为
UpdateMode="Always"
Try changing to
UpdateMode="Always"