我试图在不使用Updatepanel的情况下将裁剪后的图像加载到asp:image中。但问题是它显示图像但需要加载$('。image-cropper')。每个(linkUp); jQuery(window).load()中存在的函数,用于启动裁剪过程。但是使用RegisterClientScriptBlock方法它不会触发该函数。注意:$('。image-cropper')。each(linkUp);只有在使用新图像更新图像后才能启动。谁能让我知道错误在哪里?
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ImageResizer;
using System.Text;
public partial class Advanced : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ScriptManager1.RegisterAsyncPostBackControl(Button1);
if(!IsPostBack)
Image1.ImageUrl = "fountain-small.jpg?width=300";
if (Page.IsPostBack && !string.IsNullOrEmpty(img1.Value))
ImageBuilder.Current.Build("~/"+ImageResizer.Util.PathUtils.RemoveQueryString(img1.Value), "~/cropped.jpg", new ResizeSettings(img1.Value));
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "cropped.jpg?width=300";
UpdatePanel1.Update();
string key = "executeCropScript";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), key, "<script
type=\"text/javascript\">jQuery(window).load();</script>", false);
}
}
答案 0 :(得分:1)
使用按钮的添加属性属性。
e.g
Button1.Attributes.Add("onclick", "return:javascript functionname()");
答案 1 :(得分:0)
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button:first").click(function () {
update($("span:first"));
});
$("button:last").click(function () {
$("button:first").trigger('click');
update($("span:last"));
});
function update(j) {
var n = parseInt(j.text(), 10);
j.text(n + 1);
}
});
</script>
<style>
button { margin:10px; }
div { color:blue; font-weight:bold; }
span { color:red; }
</style>
</head>
<body>
<button>Button #1</button>
<button>Button #2</button>
<div><span>0</span> button #1 clicks.</div>
<div><span>0</span> button #2 clicks.</div>
</body>
</html>