Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Imagebutton onclick在updatepanel中不工作,如何使其工作?_C#_Asp.net_Updatepanel_Imagebutton - Fatal编程技术网

C# Imagebutton onclick在updatepanel中不工作,如何使其工作?

C# Imagebutton onclick在updatepanel中不工作,如何使其工作?,c#,asp.net,updatepanel,imagebutton,C#,Asp.net,Updatepanel,Imagebutton,这是计时器处理程序中的变量“link” protected void imagebutton1_Click(object sender, ImageClickEventArgs e){ string link = label1.Text; Page.ClientScript.RegisterStartupScript(this.GetType(), "OPEN", "window.open(" + link + ",'mywindow','width=200,hei

这是计时器处理程序中的变量“link”

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);
}

很难说,因为您实际上没有包含问题,但是如果您希望在UpdatePanel刷新时运行一段客户端代码,请使用客户端

此外,您正在使用服务器端事件执行客户端操作。请改用
OnClientClick
处理程序:

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"];
}

函数openPopUp(链接)
{
open(this.href,'mywindow','width=200,height=200',);
返回false;
}

尝试更改为
UpdateMode=“Always”
我只需在updatepanel中添加如下所示的回发触发器即可使其正常工作

<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;
}


你能发布一些代码、你的
页面加载方法的一部分以及ImageButton设置的设置(可能来自designer源文件)吗?这是你的第12个问题,同时你应该注意到一个问题应该包含超过半句话和一个“不工作”。请提供准确的错误/错误行为和相关代码。@TimSchmelter它不调用codebehind中的onclick事件。为什么要发回服务器以在客户端打开弹出窗口?您只需使用打开该弹出窗口。记住在javascript之后返回false,否则页面会发回(或者使用HTML图像和onclick事件)。编辑:您是否在clickevent处理程序中设置了断点以查看它是否被调用?@TimSchmelter我需要它在服务器中,因为我需要从数据库中获取图像和链接。我想调用imagebutton1\u单击imagebutton,当我单击imagebutton时,它不起作用。我需要它在服务器中,因为我需要从数据库中获取图像和链接数据库和onclientclick在updatepanel中仍然不起作用。
<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;
}
<Triggers>
<asp:PostBackTrigger  ControlID="ImageButton"/>
</Triggers>