【问题标题】:Need to call jQuery (window).load(function ()) using c#需要使用c#调用jQuery(window).load(function())
【发布时间】:2011-10-15 02:07:45
【问题描述】:

我需要使用 C# 调用 (window).load(function ())。无论如何我可以做到这一点。

【问题讨论】:

  • 不确定您的意思。你能用一个小例子来说明你想要完成什么吗?
  • @asawyer 我已经编辑了问题。
  • asp.net 和 asp.net-mvc 是两个截然不同的野兽。你在用什么?

标签: c# asp.net asp.net-mvc c#-4.0 c#-3.0


【解决方案1】:

用RegisterStartupScript注册你想要的任何脚本:

protected void Page_Load(object sender, EventArgs e)
{
    // Define the name and type of the client scripts on the page.
    String csname1 = "PopupScript";
    Type cstype = this.GetType();

    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname1))
    {
        StringBuilder cstext1 = new StringBuilder();
        cstext1.Append(@"$(document).ready(function() {
                                // Handler for .ready() called.
                              });");

        cs.RegisterStartupScript(cstype, csname1, cstext1.ToString(), true);
    }
}

【讨论】:

    【解决方案2】:

    不!这是不可能的。您不能在服务器端脚本中使用客户端对象。欲了解更多信息,请阅读 - Using JavaScript Along with ASP.NET

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2020-09-24
      • 1970-01-01
      相关资源
      最近更新 更多