Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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# 从C中的按钮单击事件调用jQuery函数#_C#_Jquery_Asp.net_C# 4.0_C# 3.0 - Fatal编程技术网

C# 从C中的按钮单击事件调用jQuery函数#

C# 从C中的按钮单击事件调用jQuery函数#,c#,jquery,asp.net,c#-4.0,c#-3.0,C#,Jquery,Asp.net,C# 4.0,C# 3.0,我正在尝试在不使用Updatepanel的情况下将裁剪后的图像加载到asp:image中。但问题是它显示图像,但需要加载$('.image crapper')。每个(linkUp);函数,该函数位于jQuery(window).load()中,用于启动裁剪过程。但是使用RegisterClientScriptBlock方法不会触发该函数。注:$('.image cropper')。每个(链接);应仅在使用新图像更新图像后启动。有人能告诉我错误在哪里吗 using System; using Sy

我正在尝试在不使用Updatepanel的情况下将裁剪后的图像加载到asp:image中。但问题是它显示图像,但需要加载$('.image crapper')。每个(linkUp);函数,该函数位于jQuery(window).load()中,用于启动裁剪过程。但是使用RegisterClientScriptBlock方法不会触发该函数。注:$('.image cropper')。每个(链接);应仅在使用新图像更新图像后启动。有人能告诉我错误在哪里吗

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


 }
}
使用系统;
使用System.Collections.Generic;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用图像缩放器;
使用系统文本;
公共部分高级类:System.Web.UI.Page{
受保护的无效页面加载(对象发送方、事件参数e){
ScriptManager1.RegisterAsyncPostBackControl(按钮1);
如果(!IsPostBack)
Image1.ImageUrl=“fountain small.jpg?宽度=300”;
if(Page.IsPostBack&&!string.IsNullOrEmpty(img1.Value))
ImageBuilder.Current.Build(“~/”+ImageResizer.Util.PathUtils.RemoveQueryString(img1.Value)、“~/croped.jpg”、新的大小设置(img1.Value));
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
Image1.ImageUrl=“crapped.jpg?width=300”;
UpdatePanel1.Update();
string key=“executeCropScript”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),键,“jQuery(window.load();”,false);
}
}

您可以这样尝试

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

$(文档).ready(函数(){
$(“按钮:第一”)。单击(函数(){
更新($(“span:first”);
});
$(“按钮:上次”)。单击(函数(){
$(“按钮:第一”).trigger('click');
更新($(“span:last”);
});
功能更新(j){
var n=parseInt(j.text(),10);
j、 文本(n+1);
}
});
按钮{边距:10px;}
div{颜色:蓝色;字体大小:粗体;}
span{颜色:红色;}
按钮#1
按钮#2
0按钮#1次点击。
0按钮#2次点击。

使用按钮的添加属性属性

e、 g


StackOverflow上有很多关于这方面的主题,只需搜索“jQuery代码隐藏”您是否尝试过Page.ClientScript.RegisterStartupScript?MSDN:同一用户的可能重复我可以使用此属性属性,但我想在使用c#更新面板后启动此函数。如果我这样使用,那么首先启动客户端脚本,然后启动c#代码。我使用了_udo更新面板,它工作正常。但我试图找到一种方法,通过代码本身调用函数
Button1.Attributes.Add("onclick", "return:javascript functionname()");