When my javascript is executed, the script executes properly. However the sharepoint notification it produces is supposed to simply fade out after 3 seconds, but instead, after ~2 seconds, the whole page reloads.
How can I prevent the page from reloading after my script executes?
I have the following javascript in my usercontrol.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="MoodPanelNy.VisualWebPart1.VisualWebPart1UserControl" %>
<script type="text/javascript">
function MyJavascript() {
// Displays Notification
var notification = 'Your answer has been submitted, thanks!';
var notificationId = SP.UI.Notify.addNotification(notification);
}
</script>
This is my code behind’s method Page_Load which binds the script to a button:
NotificationButton.Attributes.Add("onclick", "return MyJavascript();");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "notification", strScript, true);
Please try update:
You should use
return false;to prevent form post.