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

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.