Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my JScript1.js file code

C#
function TestAlert() {
alert("Test"):
}

ASP.NET
 <script src="Assets/Scripts/JScript1.js" type="text/javascript"></script>

<asp:Button ID="btnLogin" CssClass="login-button" runat="server" Text="Login" 
                                            OnClick="btnLogin_Click" OnClientClick="JScript1:TestAlert();"/>

the logic is not working..............
Posted
Updated 22-Jul-12 19:19pm
v2

If you are using an Embedded javascript then its good to use
VB
ClientScript.RegisterStartupScript


An example here:-


However if you want to use javascript from JScript1.js, using simple
HTML
onclientclick="TestAlert()"
is enough.
Example
 
Share this answer
 
v3
Comments
AmitGajjar 23-Jul-12 2:24am    
how you will do this using RegisterStartupScript ? are you going to read .js file and then pass text into it ???!!!!!
On ASPX Page Give The Reference of your javascript in <header> tag or header Content like Bellow....

JavaScript
<script src="../../../JScript.js" type="text/javascript"></script></script>


Call Javascript On Click Of Button Linke....

C#
<asp:linkbutton id="lnkSelectComp" onclientclick="return selectAllComp();" text="Select All" xmlns:asp="#unknown">
                        runat="server" /></asp:linkbutton>


Here JScript.js Code..

JavaScript
function selectAllComp() {
    
    var companies = document.getElementById('ctl00_ContentPlaceHolder1_listCompany');
    var optLength = companies.options.length;
    for (var i = 0; i < optLength; i++) {
        companies.options[i].selected = true;
    }
    return false;
}


Thank You,
Hope It Will Help You.
 
Share this answer
 
v2
Hi,

Everything is correct from your code. the only problem i can see is about locating your javascript file. Please use FireBug[^] to see if your javascript file is loaded from correct location ?

Hope you will find your issue yourself.

Thanks
-Amit Gajjar.
 
Share this answer
 
Change the OnclientClick with javascript method name.

<asp:button id="btnLogin" cssclass="login-button" runat="server" text="Login" xmlns:asp="#unknown">
OnClick="btnLogin_Click" OnClientClick="TestAlert();"/>
 
Share this answer
 

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