【问题标题】:Execute javascript function in c#.net. What am i doing wrong?在 c#.net 中执行 javascript 函数。我究竟做错了什么?
【发布时间】:2012-06-26 14:40:43
【问题描述】:

我想在 c# 代码中执行一个 javascript 函数。这是我所做的:

string jscript = "$(function () { $('#dialog-modal').dialog('open'); });";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", jscript, true);

我不知道该怎么做,我不明白这种方法是如何工作的

谢谢:)

obs.: 我只写了“clientScript”,但我不知道它是如何工作的

我的 Javascript:

<script type="text/javascript">
$(function () {

            $("#dialog:ui-dialog").dialog("destroy");

            var fancyboxInitOld = jQuery("#dialog-modal").dialog({
                autoOpen: false,
                height: 200,
                width: 370,
                modal: true

            });
            fancyboxInitOld.parent().appendTo(jQuery("form:first"));


        });
</script>

我的 C# 代码

try
        {
            client.Send(message);
        }
        catch
        {
            string jscript = "$('#dialog-modal').dialog('open');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "clientScript", jscript, true);
            }

【问题讨论】:

标签: c# javascript function call


【解决方案1】:

改用RegisterStartupScriptMethod

string jscript = "$(function () { $('#dialog-modal').dialog('open'); });";
Page.ClientScript.RegisterStartupScript(this.GetType(),
  "clientScript", jscript, true);

我看到你已经在 catch 块中这样做了。 RegisterClientScriptBlock 用于渲染客户端代码以供以后使用,例如某些功能。

【讨论】:

  • RegisterStartupScriptMethod 变红 :(
【解决方案2】:

试试

string jscript = "$('#dialog-modal').dialog('open');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "clientScript", jscript, true);

【讨论】:

  • RegisterStartupScriptMethod 变红
  • 使用 this 代替 Pagetypeof(object) 代替 this.GetType() 可以帮忙吗?
  • 您是否遇到上述服务器端或 javascript 错误?
猜你喜欢
  • 2013-08-06
  • 1970-01-01
  • 2015-08-26
  • 2020-08-19
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 2014-09-13
  • 2019-12-23
相关资源
最近更新 更多