如何在ASP.Net中使用JavaScript [英] How to use JavaScript in ASP.Net

查看:81
本文介绍了如何在ASP.Net中使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是javascript学习者,我按下单击按钮编写以下代码来显示DialogBox。但它给出了错误。请帮助.....

错误: - 错误1'ASP.default_aspx'不包含'LoadJScript'的定义,也没有扩展方法'LoadJScript'接受类型'ASP的第一个参数。可以找到default_aspx'(你是否缺少using指令或程序集引用?)



I m javascript learner and i hv written following code to Show DialogBox on a button click. but it gives error. please help.....
Error :- Error 1 'ASP.default_aspx' does not contain a definition for 'LoadJScript' and no extension method 'LoadJScript' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)

<head runat="server">
    <title>Demo Page for Test</title>
    <script language="javascript" type="text/javascript" >
    function LoadJScript()
    {
        // document.getElementById("label1").
        var name = prompt("Enter Your Name Here",MERAZ);
    }
    </script>
</head>







<body> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="LoadJScript()" /></body>

推荐答案

搜索使用此方法名称的所有内容LoadJScript



我相信在服务器控件中你正在使用这种方法。

如果我没有错检查你是否在服务器控件的onclick事件上调用这个方法并传递一个参数,

检查搜索(Cntr + f)此方法名称,使用ClientClick属性代替onClick调用javascript方法



希望这可以帮助你
search where all you are using this method name "LoadJScript"

I believe somewhere in server control you are using this method.
if i am not wrong check if you are calling this method on onclick event of server control and passing one parameter,
to check search (Cntr+f) this method name, and use ClientClick property instead onClick to call javascript method.

Hope this helps you


尝试 OnClientClick 而不是 OnClick

Try OnClientClick instead of OnClick:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="LoadJScript()" />


我想你也应该尝试这个..

写下这个:

I think you should also try this one..
write this in head :
<script language="javascript" type="text/javascript">
        function LoadJScript() {


            var message = "Enter Your Name Here";

            alert(message);
        }
    </script>



并将其写入正文:


and write this in body :

<input type="button" onclick="LoadJScript()" value="Click" />


这篇关于如何在ASP.Net中使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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