Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?)

XML
<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>


ASP.NET
<body> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="LoadJScript()" /></body>
Posted
Updated 29-Jul-13 2:07am
v4
Comments
Dholakiya Ankit 29-Jul-13 6:05am    
<body> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return LoadJScript()" /></body>

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
 
Share this answer
 
Comments
Ankur\m/ 29-Jul-13 6:14am    
5!
[no name] 29-Jul-13 7:00am    
THANKS! ACCORDING TO UR SUGGESTION I USE OnClientClick EVENT AND REMOVED runat="server" property
now it works properly.
kishore sharma 29-Jul-13 7:40am    
welcome always
Try OnClientClick instead of OnClick:
ASP.NET
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="LoadJScript()" />
 
Share this answer
 
Comments
Ankur\m/ 29-Jul-13 6:13am    
He just edited his code to add how he was calling the function in the button. And I was wondering why this html code would give an error.
Btw 5 to you!
Thomas Daniels 29-Jul-13 6:16am    
Thank you!
[no name] 29-Jul-13 7:01am    
THANKS! ACCORDING TO UR SUGGESTION I USE OnClientClick EVENT AND REMOVED runat="server" property
now it works properly.
Thomas Daniels 29-Jul-13 7:43am    
You're welcome!
Joezer BH 29-Jul-13 8:07am    
5ed
I think you should also try this one..
write this in head :
XML
<script language="javascript" type="text/javascript">
        function LoadJScript() {


            var message = "Enter Your Name Here";

            alert(message);
        }
    </script>

and write this in body :
C#
<input type="button" onclick="LoadJScript()" value="Click" />
 
Share this answer
 
v2
Simply replace your onClick with onClientClick... and problem will be solved... :)
 
Share this answer
 
Comments
Joezer BH 29-Jul-13 8:08am    
5ed
VICK 30-Jul-13 0:31am    
thnx
Using the following line to add ur code:
HTML
<input type="button"  önclick="LoadJScript()" value="Click" />
 
Share this answer
 
v3
If you want to use onClick have to use return key word. Once your java script return true it will go for server side click event.


C#
<asp:button id="Button1" runat="server" text="Button" onClick="return LoadJScript();" xmlns:asp="#unknown" />


<script language="javascript" type="text/javascript" >
    function LoadJScript()
    {
       var name = prompt("Enter Your Name Here","MERAZ");
       if(name!=null)
       { 
          //your logic here
          return true;
       }
       else
       {
         //your logic here
         return false;
       }       
    }
</script>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900