English 中文(简体)
如何正确调用 Page. clientScript 中的函数 。
原标题:How to call a function in Page.ClientScript properly

有两件事我不太明白

首先,有本格式的笔记本

function Allocate()
{
    this.Name = $("allocateName");
    this.AddAllocation = $("addAllocation");
    this.setCustom= $("setCustom");
}
... some other initializations here
Allocate.prototype.EnableAllocations = function() {

 this.enableAllAlloactions();
 this.setCustomAllocations();
}

这只是一个例子, 所以在 Javascript 中, 这是某种类吗? 这是在名为 Discription. js 的文件中 。

我的问题如下:

如果我在 < code> Page. clientScript. registerClientScriptBlock (...) 中调用“ 启用位置” 。 我该怎么做?

最佳回答

您应该试看分配对象, 并调用它的“ 启用分配” 函数 。

  var alloc = new Allocate();
  alloc.EnableAllocations;

这样你就可以用这样的代码创建一条字符串, 然后通过它:

  Page.ClientScript.RegisterClientScriptBlock("key",
     "var alloc = new Allocate();alloc.EnableAllocations;");
  • NOTE: you can use this.GetType().FullName as key. You shouldn t use the same key for different scripts.

此方法已被废除 。 请使用 < a href=" http://msdn. microsoft.com/ en- us/library/ system.web. ui. clientscripmanager. register. registercliptscriptstructionblock. aspx" rel = "nofollow" > ClientScriptManager. RegisterClientScriptBlock 方法( 取决于您使用的框架的哪个版本 ) 。

最后,我不知道您正在使用哪个图书馆,但 $() <() 来自某个图书馆。因此,该图书馆以及 allateName addAlplace 等等都依赖该图书馆。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签