繁体   English   中英

问题在于调用JScript函数

[英]Issue is in calling JScript function

我正在使用SpeechSynthesizer,因此从文本转换为语音。

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Speak("Hello");

//JScript function call
Label1.Text = "<script type='text/javascript'>TestMethod();</script>";
}

在上述情况下,JScript方法未触发。 但是如果我注释synth.Speak(“ Hello”);,则使用相同的代码; 完美地调用它的JScript方法。

谁能说出为什么在上述情况下JScript函数没有触发并且可以替代吗?

您可以通过从hjavascript函数内部调用http处理程序来组合javascript功能。 您也可以实现某种类型的Web服务RESTSOAP 这些服务器端服务将包含功能背后的代码(例如,SpeechSynthesizer synth = new SpeechSynthesizer(); synth.Speak(“ Hello”);)。

可以使用ASP.NET页面生命周期之外的特定html按钮上注册的javascript事件(例如onclick )来调用上述每个方法。 例如,您可以在onclick事件上调用此函数( targetURL将由http处理程序的URL或相应服务替换):

<button onclick="httpGetRequest('targetURL')">Click me</button>

function httpGetRequest(theUrl)
{

    //do something before code behind
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false );
    xmlHttp.send( null );
    return xmlHttp.responseText;

    //do something after code behind
}

希望我能帮上忙!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM