asp:ImageButton and onClientClick and page refresh

R

rum23

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
 
D

Disa

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top