调用在C#中的JavaScript功能 [英] calling a javascript function in C#

查看:143
本文介绍了调用在C#中的JavaScript功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想表现出或根据查询隐藏重复的记录。所以,我需要知道如何调用从C#codebehind的JavaScript功能。

Hi i wanted to show or hide duplicate records according to query. So, I need to know how to call the javascript function from C# codebehind.

  <a onclick="Grid1.insertRecord(); return false;" id="a2"  href="javascript:">Save</a>

当我点击保存我需要证明我所用JavaScript编写的弹出。

When I click save i need to show a popup which i have written in javascript.

 if (!exist)//exists is the query
        {
            System.Web.UI.Control my = FindControl("a2");
              a2.Attributes.Add("onclick", "retrun HideDuplicate()");

这行会返回一个错误说A2在目前的情况下不列入存在。

This line returns an error saying "a2 doesnot exist in current context."

推荐答案

MSDN文档的程序化的创建客户端回调不回发例子,其中$ C $Ç背后,是用C#可能会给它是如何认为的一般工作一个很好的概述。

MSDN documentation for programatic creation of client side callbacks without postback with an example where the code behind is in C# might give a good overview of how it is supposed to work in general.

在你的情况,相应的code-背后应该实现的接口ICallbackEventHandler和这两种方法它描述。此外,您需要两个客户端的JavaScript函数prepare和处理的回调,除了遗嘱执行人/调用(在你的情况下,保存的方法)。然而另外两个JavaScript函数人们可以在codebehind进行登记,作为示例显示。

In your case, the corresponding code-behind should implement the interface 'ICallbackEventHandler' and the two methods it describes. In addition, you would need two more client side Javascript functions to prepare and handle the callback, besides the executor/invoker (in your case, a 'save' method). However one of the additional two Javascript functions could be registered in the codebehind, as the example shows.

这篇关于调用在C#中的JavaScript功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆