ASP C # | MessageBox continues to show

I have a JavaScript MessageBox that keeps showing when I click events in the repeater or refresh the current page.

Here is the function:

public myFunctions()
{

}
/** Display Successs/Error Message **/
public void DisplayUserMessage(string messageType, string messageString, Label ErrorMessageLabel)
{
    ErrorMessageLabel.Visible = true;
    ErrorMessageLabel.Text = "<b>" + messageType.Substring(0, 1).ToUpper() + messageType.Substring(1).ToLower() + ":</b> " + messageString;
    ErrorMessageLabel.CssClass = messageType.ToLower() + "_message";
}
public void HideUserMessage(Label ErrorMessageLabel)
{
    ErrorMessageLabel.Visible = false;
    ErrorMessageLabel.Text = "";
    ErrorMessageLabel.CssClass = "";
}

Here is jquery to make it fade:

$(document).ready(function () {
/** Success/Error Messages **/
$('.success_message').animate({ opacity: 1.0 }, 2000).fadeOut('slow');
$('.error_message').animate({ opacity: 1.0 }, 2000).fadeOut('slow');

});

Here it is on MasterPage:

<!-- Message Box -->
<div id="msgBox" runat="server">
      <asp:Label ID="ErrorMessageLabel" CssClass="" runat="server" Visible="false"></asp:Label>
</div>

Here is the script code in the code when success occurs:

Label ErrorMessageLabel = (Label)Master.FindControl("ErrorMessageLabel");
new myFunctions().DisplayUserMessage("success", "Administrator Updated!", ErrorMessageLabel);

Does anyone know how I can stop it due to the constant appearance after clicking another button or refreshing the page?

+3
source share
3 answers
if(IsPostBack)
         new myFunctions().HideUserMessage(ErrorMessageLabel);

It worked. Thanks @Harie

0
source

. reset . , .

<input id="txtHidSuccess" type="hidden" runat="server" />

txtHidSuccess.Value = "0";

/

txtHidSuccess.Value = "1";

JQuery

$(function(){
    if ($("#txtHidSuccess").val() === "1") {
        /** Success/Error Messages **/
       $('.success_message').animate({ opacity: 1.0 }, 2000).fadeOut('slow');
       $('.error_message').animate({ opacity: 1.0 }, 2000).fadeOut('slow');    
    }
});
+1

, DisplayUserMessage(), HideUserMessage(). , ErrorMessageLabel, , .

, Label ASP.NET, div CSS, . , ClientScriptManager.RegisterStartupScript(), script , div. div, .

0

Source: https://habr.com/ru/post/1780342/


All Articles