jump to navigation

How To Stop Ajax Post Back when A button contains OnClick() and onclientclick events November 28, 2008

Posted by venkatworld in Uncategorized.
add a comment
When A button Contains Two event functions ,one on client side and the other on Server side, The Page posts back  event occurs even when the page not pass  the validation.
 
To Avoid this unwanted postback ,we should  explicitly call
the method
 
Page_ClientValidate() in the javascript event method or function.
 
Here is the Example:
<

asp:ImageButton ID=”imgBtnSubmit” CssClass=”image” ValidationGroup=”Submit” onclientclick=”javascript:if(Page_ClientValidate())return HaspopUpClosed(); “ OnClick=”imgBtnSubmit_Clicked” runat=”server” ImageUrl=”~/res/images/img/Updatebtn.jpg” />

Javascript function overloading November 28, 2008

Posted by venkatworld in Uncategorized.
Tags: ,
add a comment

JavaScript function overloading..!

 

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head >

    <title>Javascript Function calls.</title>

<script language=”javascript” type=”text/javascript” >

     

    function Add()

    {

      alert(‘Add With No Parameters ‘);

    }

   

    function Add(val1,val2)

    {

      alert(‘Add With Two Parameters ‘+(val1+val2));

    }

    function Add(val1)

    {

      alert(‘Add With one Parameter ‘+val1);

    }

 

    function Add(val1,val2,val3)

    {

      alert(‘Add With Three Parameters ‘+(val1+val2+val3));

    }

  

</script>

</head>

<body>

  

    <form id=”form1″>

    <div style=”width:500px; height:400px; background-color:Gray;” >

    <input type=”button” onclick=”Add(5,6,7);” value=”Add with Three Parameters” />

    <input type=”button” onclick=”Add(5,6);” value=”Add with Two Parameters” />

    <input type=”button” onclick=”Add(5);” value=”Add with One Parameters” />

    <input type=”button” onclick=”Add();” value=”Add with No Parameters” />

    </div>

    </form>

</body>

</html>

 

What is the out put of the above code, when we click on the button with value ‘Add with No Parameters’ or any other button.?

 

If we expect the alert message 

 

  alert(‘Add With No Parameters ‘);

 

And if we say whenever we click on a button, its corresponding Add function will be called,we are  absolutely wrong.If you have any doubt run this code.

 

Whatevr the button we click,

 

 alert(‘Add With Three Parameters ‘+(val1+val2+val3));

 

 will be called irrespective of the javascrpt function signature.

 

Javascrit won’t suport function overloading.When we define a function with the same name but with different parameters,the function call directly goes to the function which is defined at the last. i.e. the last function in the order.

 

If we change the order of the functions,the function which is last in the definitions will be called.

 

Here whats happening is, the  function which is defined at the last will overwrite the previously defined functions.

Hello world! September 8, 2008

Posted by venkatworld in Uncategorized.
1 comment so far

Welcome to Venkat’World……..!

I am  here to share my Thoughts….and Ideas….!..!

So……keep browsing…….for updates……!