如何从.cs文件C#调用JavaScript/jQuery函数 [英] How to call JavaScript/jQuery function from .cs file C#

查看:122
本文介绍了如何从.cs文件C#调用JavaScript/jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理asp.net(C#)项目,该项目包括一些页面文件(aspx,aspx.cs)和一些唯一的(.cs)文件.我可以使用scriptregister从页面文件(aspx,aspx.cs)访问JavaScript/jQuery函数.但是我的问题是如何从(.cs)文件访问JavaScript/jQuery函数.我正在(.cs)文件中生成一些html标签,因此需要从(.cs)类调用JavaScript/jQuery函数.

I'm working on asp.net (C#) project which include some page files (aspx, aspx.cs) and some only (.cs) file. I'm able to access JavaScript/jQuery functions from page files (aspx, aspx.cs) using scriptregister. but my question is how can I access the JavaScript/jQuery functions from (.cs) files. I'm generating some html tags in (.cs) file therefore in need of to call JavaScript/jQuery function from (.cs) classes.

我拥有的文件是(例如):

The files I have are(for example):

  • Default.aspx
  • Default.aspx.cs
  • 和Web.cs(我的担心是要从web.cs调用JavaScript/jQuery函数)

实际上,我想做的是在Web.cs(业务对象)中生成一些HTML代码,而在web.cs中生成HTML代码时,我需要由jQuery函数生成的其他一些动态HTML代码,其输出是我的关注:var output ="My HTML Code Generated by jQuery function"

Actually, What I'm trying to do is to generate some HTML code in Web.cs (Business Object) and while generating HTML code in web.cs i need some other dynamic HTML code generated by jQuery function which output is my concern: var output ="My HTML Code Generated by jQuery function"

现在,我需要上面的jQuery输出与Web.cs HTML代码生成合并.

Now I need the above jQuery output to merger with Web.cs HTML code generating.

请告诉我如何才能从web.cs调用jQuery函数并将结果从jQuery返回到web.cs以便合并?

Kindly let me know how can it be possible to call jQuery function from web.cs and get back the result from jQuery to web.cs in order to merger?

谢谢

推荐答案

脚本注册实际上发生在页面"对象上,即Web.cs无权访问该页面来注册脚本.例如,如果要Web.cs在Default.aspx页上注册脚本,则需要通过接口或类定义授予对Default.aspx/cs"Page"对象的Page.ClientScript.RegisterClientScriptBlock方法的访问权限.

The script registration actually happens on the "Page" object, i.e. Web.cs does not have access to the page to register a script. For example, if you want Web.cs to register a script on Default.aspx page, you'd need to give access to the Default.aspx/cs "Page" object's Page.ClientScript.RegisterClientScriptBlock method through an interface or class definition.

这篇关于如何从.cs文件C#调用JavaScript/jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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