Click here to Skip to main content
11,637,415 members (57,928 online)
Rate this: bad
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 1:32am
Edited 1-Jun-12 1: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 at 1-Jun-12 8:27am
it will surely work tested. you can try this.
preet88 at 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
0 OriginalGriff 295
1 stibee 288
2 270
3 Sergey Alexandrovich Kryukov 224
4 himanshu agarwal 184
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,643
2 Mika Wendelius 6,959
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web02 | 2.8.150728.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