IT Community - Software Programming, Web Development and Technical Support

How to call a javascript function in a client side click?

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


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 10-10-2007, 04:28 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Question How to call a javascript function in a client side click?

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-11-2007, 04:31 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Smile Re: How to call a javascript function in a client side click?

Hi buddy,

You have to change your code as follows,

Code:
btn.Attributes.Add("onclick","return javascript:myShow()");
OR

Code:
btn.Attributes.Add("onclick",return "javascript:myShow()");
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-15-2007, 08:16 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Question Re: How to call a javascript function in a client side click?

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-15-2007, 11:34 PM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Default Re: How to call a javascript function in a client side click?

Hi,

You can try to call that javascript function inside the asp:button tag.
__________________
Raja. Myblog
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-30-2007, 01:43 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Smile Re: How to call a javascript function in a client side click?

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>");
}
}
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -7. The time now is 07:55 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0