我有更新面板内的图像控件,在页面加载我设置其网址。更新面板中的图像导致整个页面刷新
代码隐藏在Page_Load中
string url = "example.com";
Image1.ImageUrl = url;
里面的UpdatePanel在ASPX
<asp:Image ID="Image1" runat="server" CssClass="image" />
我也有几个提交UpdatePanel内的按钮,和我更新按钮点击一些texboxes和标签。
然而,这会导致整个页面刷新。 (滚动条上升。)
如果移动更新面板,这不会发生的外部形象。 问题是布局根本不起作用,如果我删除updatepanel之外的图像。 任何人都可以帮助我吗?谢谢。
UPDATE
我已经意识到这只是发生在Chrome。有人有想法吗?
UPDATE 2 在该页面上,我已通过从updatepanel中删除img来解决该问题。布局工作很糟糕,但它工作。
不过我有另外一个页面,在那里我加入新IMGS到的UpdatePanel当用户点击加载更多。同样的交易,显然我不能从这次更新面板中移出图像。这是代码。背后
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<!--Recent Uploads-->
<div class="uploads">
<h2>Uploads</h2>
<asp:UpdatePanel ID="RecentUpload" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loaduploads"/>
</Triggers>
<ContentTemplate>
<asp:Button CssClass="uploadButton" ID="loaduploads" runat="server" Text="Load More" OnClick="loaduploads_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
代码(上传指数是一个会话变量)
upload_index += 5;
for (int i = 0; i < upload_index; i++)
{
try
{
SSImage img = images[i];
HyperLink imglink = new HyperLink();
imglink.NavigateUrl = "/Image.aspx?id=" + img.id;
imglink.ImageUrl = "/ShowImage.ashx?imgid=" + img.id;
imglink.ToolTip = img.title;
imglink.CssClass = "imgupload";
Control contentpanel = RecentUpload.ContentTemplateContainer;
contentpanel.Controls.AddAt(contentpanel.Controls.Count - 2, imglink);
}
catch (ArgumentOutOfRangeException)
{
loaduploads.Visible = false;
break;
}
}
更新3
问题不与静态图像发生,而发生在我试图从加载showimage.ashx
。这里是代码。
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class ShowImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
try
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
conn = new SqlConnection(connStr);
cmd = new SqlCommand("SELECT Image_data FROM [Image_table] WHERE Image_id = " + context.Request.QueryString["imgID"], conn);
conn.Open();
Object result = cmd.ExecuteScalar();
//if nothing found throw exception
if (result == null)
{
throw new Exception();
}
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])rdr["Image_data"]);
}
if (rdr != null)
rdr.Close();
}
catch
{
}
finally
{
conn.Close();
conn.Dispose();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
有ÿ你可以在你的更新面板中添加Triggers吗? – zey 2013-04-26 06:00:29
@zey是的,我有'asyncpostbacktrigger' – btevfik 2013-04-26 06:01:58
你可以发布你的代码吗? – zey 2013-04-26 06:05:55