JavaScript to Asp page

I am learning javascript client-side scripting language and I use js in ASP .. I don’t know when I compile the code, it shows

COMPILATION ERROR: Compiler Error Message: CS1061: 'ASP.default_aspx' does not contain a definition for 'popup' and the extension method 'popup' takes the first argument, the type 'ASP.default_aspx' can be found (do you miss the using directive or the assembly reference?)

here is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WEB_test_app._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Shuraat Web ki</title>
    <script type ="text/javascript">
    function popup()
    {
    alert("popup!!");
    }    
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick ="popup()"/>

      <script type ="text/javascript">
      document.write("Abid");
      </script>   
    </div>
    </form>
</body>
</html>
+3
source share
3 answers

. popup() Javascript , OnClick , (#). popup() .

ClientClick, click . , , , false , :

<asp:Button ID="Button1" runat="server" Text="Button"
    OnClientClick ="popup(); return false;" />
+5

popup() OnClientClick Click :

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick ="popup()"/>

, OnClick #/VB.Net(Code-Behind) (, , ), , OnClientClick Javascript.

+1

OnClick - server side click handler . If you want to call javascript function use OnClientClick.

+1
source

Source: https://habr.com/ru/post/1791806/


All Articles