从C#.net的javascript函数调用 [英] calling from a javascript function from C#.net

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

问题描述

hi


我正在使用asp.net,C#.net和Javascript,我在javascript中编写了类似"callmessage()"的函数,现在我试图从C#.net调用该函数.
,我已经尝试了很多方法,在这里我将编写示例代码

情况1:

hi


I am using the asp.net and C#.net and Javascript, I had written a function like "callmessage()" in javascript and now iam trying to call that function from C#.net
, i had tried in lot of ways , here i will write the sample code

case1:

<script type="text/javascript">
function callmessage1() {
alert(''hello'');
} 
</script>



在C#.net后端的服务器端代码中



in serverside code in backend from C#.net

 protected void Button1_Click(object sender, EventArgs e)
    {        HttpContext.Current.Response.Write("<script>callmessage1();</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "btn", "<script type = 'text/javascript'>callmessage1();</script>");//siva
 ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "callmessage1();", true);
}




这不起作用

但是当我这样做时,它正在工作
案例2:






this is not working

but when i do like this it was working
case2:



 protected void Button1_Click(object sender, EventArgs e)
    {
HttpContext.Current.Response.Write("<script>alert('its working');</script>");

ClientScript.RegisterClientScriptBlock(this.GetType(), "btn", "<script type = 'text/javascript'>alert('its working');</script>");//siva
 ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('its working');", true);
} 



谁能给我指定我在做什么的错误,只是我需要调用该函数,而且在另一个项目中,相同的代码正在工作,并且我得到了最好的结果,但是为什么在这个项目中

我想念的任何东西...........


C#.net中是否有可能内联javascrift代码

请从这里帮忙
谢谢Q .. !!



can anyone please specify me the Mistake where i am doing , just i need to call the function,moreover in another project the same code is working , and i am getting the best result, but why in this project

anything i am missing...........


is there any chance of inline javascrift code in C#.net

Please help out from here
thank Q..!

推荐答案

您可以从c#代码中调用javascript函数.
ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(),"showNotify","YourJavascriptMethod",true);

您不需要在其中包含脚本标签,因为最后一个参数"true"将自动添加它们.
You can call javascript function from c# code.
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "showNotify", "YourJavascriptMethod", true);

You don''t need to include script tags there as the last parameter ''true'' will automatically add them.


关注链接:

http://stackoverflow.com/questions/5731224/calling-javascript-function-from-codebehind [ ^ ]
http://forums.asp.net/t/1363655.aspx [ http://social.msdn.microsoft.com/Forums/是/csharpgeneral/thread/786c041a-e4f8-48d8-9340-a59d3f307878 [
follow the links:

http://stackoverflow.com/questions/5731224/calling-javascript-function-from-codebehind[^]
http://forums.asp.net/t/1363655.aspx[^]
http://social.msdn.microsoft.com/Forums/is/csharpgeneral/thread/786c041a-e4f8-48d8-9340-a59d3f307878[^]


Thanks,
Ambesha


好的.
如何从ASPX.CS文件中的代码了解在ASPX文件中编写的callmessage1()函数.

如果您想在这种情况下使用后面的代码运行JS,请
y

您已经在.CS文件中写入了整个脚本



将此功能添加到按钮的HTML标签中,例如

Okay .. explainantion is simple ..

How a code from your ASPX.CS file will come to know about your callmessage1() function which is written in your ASPX file.

If you want to run a JS from code behind in that case
y

you have write entire script in .CS file

OR

Add this function in HTML tag of your button like

<asp:button id="Button1" usesubmitbehavior="false" onclientclick="javascript:callmessage1(); /> </pre></xml>" xmlns:asp="#unknown"></asp:button>


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

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