0

how to prevent refresh on asp.net c# web page button?

protected void Button1_Click(object sender, EventArgs e)
{

}

Regards

4
  • Do you mean a refresh of data if its a postback?? You need to make your question more descriptive as its difficult to understand what you're trying to achieve Commented Dec 16, 2011 at 17:01
  • Buttons are meant to post data to server in general. You can use Ajax at the most. Commented Dec 16, 2011 at 17:02
  • Your question doesn't make sense. Commented Dec 16, 2011 at 17:02
  • <asp:Button OnClientClick="return false" OnClick="Button_Click" runat="server" /> , in that case the use of Button will be showpiece in your page. Commented Dec 16, 2011 at 17:03

3 Answers 3

1

you must use this way :

<asp:button ID="btn" runat="server" Text="Button" onClientclick="btn_Click(event);">     </asp:button>
<script>

function btn_Click (e)
{

    if(//Check somthing)
          e.preventDefault();

}

</script>
Sign up to request clarification or add additional context in comments.

Comments

0

Short answer, you can't.

However, using methods such as ajax, you can hide the appearance of the postback.

Comments

0

you can do it by creating a cookie inside your Button1_Click method. The first instruction within this method should check if that cookie exists or has not expired. In case itdoesn't exist or it expired, the follow line will create or update the cookie. In case the cookie exists, return; Sorry i cant give code cause im using my mobile.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.