asp:ImageButton and onClientClick and page refresh

Discussion in 'ASP .Net Web Controls' started by rum23, Nov 28, 2008.

  1. rum23

    rum23 Guest

    I have an asp:ImageButton on the page and it calls a javascript method
    onClientClick attribute. The javascript method simply clears the text box
    fields.
    However, after clearing the text boxes, the page refreshes too and I don't
    want the page refresh. How can I avoid this?

    <asp:ImageButton ID="lbkClearLineItems" runat="server"
    CausesValidation="True" ToolTip="Clear items"

    OnClientClick="javascript:ClearLineItemData(this);"
    ImageUrl="~/CIP/Images/deleteIcon.jpg" />


    javascript function is as follows

    function ClearLineItemData(therow)
    {
    var sControlName = therow.name;
    sControlName = sControlName.replace("lbkClearLineItems", "");
    document.getElementById(sControlName + 'txtamtfoot').value = "";
    document.getElementById(sControlName + 'txtitemfoot').value = "";

    }

    Please help.

    Thanks
     
    rum23, Nov 28, 2008
    #1
    1. Advertising

  2. rum23

    Disa Guest

    You have to return false to cancel the postback as below

    function CheckStatus()
    {
    var divLayer = document.getElementById('Div1');

    if(divLayer.style.display == 'block')
    {
    divLayer.style.display = 'none';
    }
    else
    {
    divLayer.style.display = 'block';
    }

    return false;
    }

    Now you can add at page_load event the onclick event of the button to call
    the above javascript function

    Button1.Attributes.Add("onclick","return CheckStatus();");

    -disa
     
    Disa, Jan 24, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cHBhdGVs?=

    ImageButton problem with page refresh

    =?Utf-8?B?cHBhdGVs?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,174
    bruce barker
    Apr 19, 2004
  2. Nathan Sokalski
    Replies:
    3
    Views:
    7,560
    Teemu Keiski
    Aug 1, 2007
  3. =?Utf-8?B?RWFnbGVSZWRASGlnaEZseWluZ0JpcmRzLmNvbQ==

    ImageButton OnClientClick Events Not Firing on Client

    =?Utf-8?B?RWFnbGVSZWRASGlnaEZseWluZ0JpcmRzLmNvbQ==, Nov 14, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    4,958
    Aaron
    Nov 30, 2007
  4. ppatel

    ImageButton problem with page refresh

    ppatel, Apr 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    167
    bruce barker
    Apr 19, 2004
  5. Nathan Sokalski

    Problem with ImageButton.OnClientClick when DataBinding

    Nathan Sokalski, Jul 31, 2007, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    791
    Teemu Keiski
    Aug 1, 2007
Loading...

Share This Page