Click here to Skip to main content
11,932,446 members (61,897 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
hi friends,

i'm calling two javascript functions on button click after adding them on pageload
as follows:
btnSave.Attributes.Add("onclick", "return btnClickValidation();btn();"); 

here btnClickValidation(); returns either true or false.
and hence btn(); doesnot executes
however if I swap the calling order it works well..

Other thing that i want to do is I want to call the btn(); when postback happens... Is this possible? If yes Then how
Thanks in advance
Posted 1-Jun-12 2:32am
Edited 1-Jun-12 2:36am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

//Keep as is simple
function Onclick()  {
    var b = btnClickValidation();
    if (b)
    return b;
and then
btnSave.Attributes.Add("onclick", "return Onclick();");
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

simply you can call the function btn in btnClickValidation() function because when we return than it will no go to your second js function btn or you can use it as .

btnSave.Attributes.Add("onclick", "var a=btnClickValidation(); if (a == true) {btn();} else { return false;}"); 
Prosan 1-Jun-12 8:27am
it will surely work tested. you can try this.
preet88 5-Jun-12 1:19am
thanks i have done some similar kind of code in javascript itself thanks for your help.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 1 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100