bte*_*fik 9 html c# asp.net updatepanel
我在更新面板内有一个图像控件,在页面加载我正在设置它的URL.
page_load中的代码
string url = "example.com";
Image1.ImageUrl = url;
Run Code Online (Sandbox Code Playgroud)
在aspx中的updatepanel内部
<asp:Image ID="Image1" runat="server" CssClass="image" />
Run Code Online (Sandbox Code Playgroud)
我还在更新面板内有几个提交按钮,我正在按钮点击更新一些texbox和标签.
但是这会导致整个页面刷新.(滚动条上升.)
如果将图像移到更新面板之外,则不会发生这种情况.问题是如果我删除updatepanel之外的图像,布局根本不起作用.谁能帮我这个?谢谢.
UPDATE
我意识到这只发生在Chrome中.有没有人有想法?
更新2 在该页面上,我通过从updatepanel中删除img解决了该问题.让布局工作真是太棒了,但它确实奏效了.
但是我有另一个页面,当用户点击加载更多时,我在updatepanel中添加新的imgs.同样的交易,显然我这次不能将图像移出更新面板.这是代码.
<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>
Run Code Online (Sandbox Code Playgroud)
代码隐藏(上传索引是会话变量)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
更新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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
您应该使用更新面板的异步回发触发器,这里是示例:
<asp:AsyncPostBackTrigger ControlID="" EventName=""/>
Run Code Online (Sandbox Code Playgroud)
其中“controlID”是可以导致回发的元素的 ID,“eventname”是由定义的控件触发以导致回发的特定事件
| 归档时间: |
|
| 查看次数: |
2347 次 |
| 最近记录: |