如何从c#中的代码调用javascript函数 [英] how to call javascript function from code behind in c#

查看:89
本文介绍了如何从c#中的代码调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据代码背后的条件调用javascript警报函数showalert()。

我的代码:

if(CheckBox1.Checked == false)

{

---- < br $>
}

其他

{

button.Attributes.Add(onclick,javascript:return ShowAlert( );;);

response.redirect(#);

}

但它不起作用。

解决方案

嗨!!!看看这个链接!!

使用ScriptManager.RegisterStartupScript从后面的代码调用javascript函数 [ ^ ]



http://www.aspdotnet-suresh.com/2010/08/calling-javascript-function-from.html [< a href =http://www.aspdotnet-suresh.com/2010/08/calling-javascript-function-from.htmltarget =_ blanktitle =New Window> ^ ]


使用ClientScriptManager.RegisterStartupScript方法



http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.regist erstartupscript.aspx [ ^ ]


button.Attributes.Add(OnClientClick,javascript:return ShowAlert(););

< pre lang =cs> txtItemName.Attributes.Add( OnKeypress 返回FocusOnEnterAll('& txtDescription.ClientID& ',event);


i want to call javascript alert function showalert() based on condition in code behind.
My code :
if (CheckBox1.Checked == false)
{
----
}
else
{
button.Attributes.Add("onclick", "javascript:return ShowAlert();");
response.redirect("#");
}
but it''s not working.

解决方案

Hi!!! take a look of this link!!
Call to javascript Function from code behind using ScriptManager.RegisterStartupScript[^]

http://www.aspdotnet-suresh.com/2010/08/calling-javascript-function-from.html[^]


use ClientScriptManager.RegisterStartupScript Method

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx[^]


button.Attributes.Add("OnClientClick", "javascript:return ShowAlert();");

txtItemName.Attributes.Add("OnKeypress", "return FocusOnEnterAll('" & txtDescription.ClientID & "',event);")


这篇关于如何从c#中的代码调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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