本文介绍了如何从代码隐藏中执行Javascript ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我注册这样的客户端脚本; ---------------------- -------------------------------------------------- - ----------- Public Sub CreateClientAlert(ByVal Message As String,ByVal objPage As Page ) Dim StrScript作为新的StringBuilder("") 使用StrScript .Append("< script type =" " text / javascript"">") .Append(vbCrLf) 。附近(vbCrLf) .Append( " alert(''"& Message&"'');") .Append(vbCrLf) .Append("< / script>") 结束 如果不是 objPage.ClientScript.IsClientScriptBlockRegistered(" AlertBox")那么 objPage.ClientScript.RegisterClientScriptBlock(Me.GetType, " AlertBoX",StrScript.ToString) 结束如果 结束Sub ----------------------------------------- --------------------------------- --------- - 但是如何从代码隐藏中执行javascipt? (例如来自buttonclick event ....) 感谢所有帮助... Hakan?rnekHi ,I register client scripts like this;-------------------------------------------------------------------------------------Public Sub CreateClientAlert(ByVal Message As String, ByVal objPage AsPage)Dim StrScript As New StringBuilder("")With StrScript.Append("<script type=""text/javascript"">").Append(vbCrLf).Append(vbCrLf).Append("alert(''" & Message & "'');").Append(vbCrLf).Append("</script>")End WithIf NotobjPage.ClientScript.IsClientScriptBlockRegistered ("AlertBox") ThenobjPage.ClientScript.RegisterClientScriptBlock(Me. GetType,"AlertBoX", StrScript.ToString)End IfEnd Sub-------------------------------------------------------------------------------------but how can I execute javascipt from codebehind ? ( ex. from buttonclickevent....)Thanks for all helps...Hakan ?rnek推荐答案 从技术上讲,你不能从代码隐藏中执行Javascript。但是,你可以做的是为输出HTML添加一个OnClick事件处理程序,并允许 浏览器在单击按钮时执行javascript :-) 因此,在按钮中添加OnClick按钮。属性。Technically speaking you can''t execute Javascript from codebehind. But whatyou can do is add a OnClick event handler to the output HTML and allow thebrowser to execute javascript when the button is clicked :-)So, in your button, add an "OnClick" attribute. 这篇关于如何从代码隐藏中执行Javascript ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-11 09:22