立即在ASP.NET代码中运行Javascript。 [英] Running Javascript inside ASP.NET code instantly.

查看:64
本文介绍了立即在ASP.NET代码中运行Javascript。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我希望你能解决我的问题。我正在ASP.NET代码中执行SQL查询,我正在使用bing的javascript API。问题是我需要在运行查询之前执行javascript函数。此功能基于字符串格式的地址提供地理坐标。我已经知道 RegisterStartupScript RegisterClientScriptBlock ,但这两个对我不起作用,因为javascript由于某种原因没有执行。这是代码。而且,我差点忘了,脚本在页面的头部正确声明。



Hello everyone, I hope you can help me with my problem. I am executing a SQL query inside ASP.NET code and I am using bing''s javascript API. Problem is that I need to do a javascript function before running a query. This function provides geocoordinates based on the address in a string format. I already know for RegisterStartupScript and RegisterClientScriptBlock, but these two don''t work for me because javascript is not executing for some reason. Here is the code. And, I almost forgot, the script is declared properly at the head of the page.

public void calculateCoordinates()
        {
            ClientScriptManager cs = Page.ClientScript;
            Type cstype = this.GetType();
            String csName = "Calculate";
            if (!cs.IsStartupScriptRegistered(cstype, csName))
            {
                String jsFunction = "calculateGeoCoordinates();";
                cs.RegisterStartupScript(cstype, csName, jsFunction, true);
            }
        }

推荐答案

using AjaxControlToolkit;

Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Write your javascript code here');", true);


使用&调用RegisterStartUpScript,RegisterClientScript和Client-Side Script [ ^ ]

http://stackoverflow.com/questions/788330/passing-arguments-to-javascript-function-from-code-behind [ ^ ]

http://social.msdn.microsoft.com/Forums/en-US/netfxjscript / thread / f474ef47-a639-4019-93eb-387d83ebb112 / [ ^ ]
Use & Call RegisterStartUpScript, RegisterClientScript and Client-Side Script[^]
http://stackoverflow.com/questions/788330/passing-arguments-to-javascript-function-from-code-behind[^]
http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/f474ef47-a639-4019-93eb-387d83ebb112/[^]


这篇关于立即在ASP.NET代码中运行Javascript。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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