本文介绍了从C#中的Button Click事件调用jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在不使用Updatepanel的情况下将裁剪后的图像加载到asp:image中.但是问题是它显示图像,但是它需要加载$('.image-cropper').each(linkUp); jQuery(window).load()中存在的用于启动裁剪过程的函数.但是使用RegisterClientScriptBlock方法不会触发该功能.注意:$('.image-cropper').each(linkUp);仅在用新映像更新映像后才应启动.谁能让我知道错误在哪里?

I am trying to load the cropped image into the asp:image without using Updatepanel. But the problem is it displays the image but it needs to load the $('.image-cropper').each(linkUp); function which is present in the jQuery(window).load() to start the cropping process. But using the RegisterClientScriptBlock method it would not fire that function. Note: $('.image-cropper').each(linkUp); should be initiated only after the image has been updated with new image. Can anyone let me know where the error is?

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


 }
}

推荐答案

使用按钮的添加属性属性.

use add attribute property of button.

例如

Button1.Attributes.Add("onclick", "return:javascript functionname()");

这篇关于从C#中的Button Click事件调用jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:34