我正在使用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函数没有触发,可能是替代它?
答案 0 :(得分:0)
您可以通过在hjavascript函数中调用http handler来结合javascript功能。您还可以实现调用某种类型的Web服务,REST或SOAP。这些服务器端服务将包含您的代码隐藏功能(例如,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
}
希望我帮忙!