This is a discussion on How to call a javascript function in a client side click? within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi all, I want to call javascript function on click event of a button. For this i have added code ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all, I want to call javascript function on click event of a button. For this i have added code like btn.Attributes.Add("onclick","javascript:myShow()" ); Now it is calling only javascript function and not executing server side click event of button. |
| Sponsored Links |
| |||
| Hi buddy, You have to change your code as follows, Code: btn.Attributes.Add("onclick","return javascript:myShow()"); Code: btn.Attributes.Add("onclick",return "javascript:myShow()"); |
| |||
| Hi, I have a asp.net page. I have a asp.net button control. I need to call a javascript for some validation and then server side code on click of this button. The server side code(on button click event is fired properly) is being called. But the javascript validation does not happen My button html script is <asp:button id="btnConvert" style="Z-INDEX: 102; LEFT: 352px; POSITION: absolute; TOP: 408px" runat="server" BackColor="#FFC080" Height="32px" Width="137px" Text="Convert" Font-Bold="True"></asp:button> My code behind page_load event has call to javascript function as below btnConvert.Attributes.Add("onclick","javascript:re turn fnValidate();"); My javascript function code is var result = true; if(window.document.getElementById('CheckK').checke d == false && window.document.getElementById('CheckL').checked == false && window.document.getElementById('CheckM').checked == false && window.document.getElementById('CheckN').checked == false && window.document.getElementById('Check35').checked == false && window.document.getElementById('Check50').checked == false) { alert("Please select at least one Compressor Size."); result = false; } else { if(window.document.getElementById('ChkAutoFemaleDa ta').checked == false && window.document.getElementById('ChkAutoMaleData'). checked == false && window.document.getElementById('ChkAutoOverallData ').checked == false && window.document.getElementById('ChkVerFemaleData') .checked == false && window.document.getElementById('ChkVerMaleData').c hecked == false && window.document.getElementById('ChkVerOverallData' ).checked == false) { alert("Please select at least one Check Box for the type of data."); result = false; } else { result = true; } } return result; } The javascript validation never gets fired. Please help.
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| WebForm1.aspx <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="testsuite.WebForm1" enableViewState="True"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script type="text/javascript"> function confirmDelete() { var x = confirm("Are you sure you want to do this?"); if (x) { return true; } else { alert("Delete cancelled."); return false; } } </script> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 32px" runat="server"></asp:TextBox> <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 32px" runat="server">Label</asp:Label> <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 192px; POSITION: absolute; TOP: 72px" runat="server" Text="Button"></asp:Button> </form> </body> </HTML> WebForm1.aspx.cs using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; namespace testsuite { /// /// Summary description for WebForm1. /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Button Button1; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here Button1.Attributes.Add("onclick","return confirmDelete();"); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { Page.RegisterStartupScript(@"startup",@"<script>al ert('Record deleted.');</script>"); } } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/4042-how-call-javascript-function-client-side-click.html | |||
| Posted By | For | Type | Date |
| DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 10-30-2007 02:20 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Client side JavaScript and and Server side Java Script | sathian | HTML, CSS and Javascript Coding Techniques | 2 | 11-09-2007 10:30 PM |
| difference between Client side JavaScript and and Server side Java Script? | Sundaram | HTML, CSS and Javascript Coding Techniques | 1 | 09-05-2007 11:46 AM |
| Which JavaScript file is referenced for validating the validators at the client side? | sundarraja | ASP and ASP.NET Programming | 1 | 07-27-2007 05:26 AM |
| Which Javascript file is referenced for validating the validators at the client side? | mobilegeek | HTML, CSS and Javascript Coding Techniques | 1 | 07-25-2007 11:15 PM |
| should validation occur server side or client side?why? | prasath | ASP and ASP.NET Programming | 1 | 07-19-2007 03:09 AM |